Skip to content

Conversation

@DiegoCardoso
Copy link
Contributor

Description

Overlay allows the vaadin-overlay-escape-press custom to be default prevented before closing. This change also allows the defaultPrevent called on the keydown event to stop the overlay from closing.

That should allow cases where, while interacting with an interactive element inside a Grid cell, hitting Esc to move the focus back to the cell, the overlay parent won't be closed, since Grid calls preventDefault on the keydown event.

To manually test it, add this snippet to the /dev/dialog.html page:

        import '@vaadin/grid';
        //...

        const grid = document.createElement('vaadin-grid');
        grid.innerHTML = `<vaadin-grid-column id="buttonColumn"></vaadin-grid-column>`;
        grid.items = [{ name: 'foo' }, { name: 'bar' }];
        container.appendChild(grid);
        const buttonColumn = grid.querySelector('#buttonColumn');
        buttonColumn.renderer = (root, _, model) => {
          if (root.firstElementChild) return;

          const button = document.createElement('button');
          button.textContent = `Button for ${model.item.name}`;
          root.appendChild(button);
        };

Fixes vaadin/flow-components#8176

Type of change

  • Bugfix

Overlay allows the `vaadin-overlay-escape-press` custom to be default
prevented before closing. This change also allows the `defaultPrevent`
called on the `keydown` event to stop the overlay from closing.

That should allow cases where, while interacting with an interactive
element inside a Grid cell, hitting <kbd>Esc</kbd> to move the focus
back to the cell, the overlay parent won't be closed, since Grid calls
`preventDefault` on the `keydown` event.

Fixes vaadin/flow-components#8176
@DiegoCardoso
Copy link
Contributor Author

With the latest change, some tests in DatePicker started to fail. preventDefault is being called here:

if (allowedKeys.indexOf(e.keyCode) === -1) {
e.preventDefault();
}
}

... for all keys, except Tab. I wasn't able to fully understand the reason from reading the comment, and I wonder if it's safe to whitelist Escape as well.

@DiegoCardoso
Copy link
Contributor Author

With the latest change, some tests in DatePicker started to fail. preventDefault is being called here:

if (allowedKeys.indexOf(e.keyCode) === -1) {
e.preventDefault();
}
}

... for all keys, except Tab. I wasn't able to fully understand the reason from reading the comment, and I wonder if it's safe to whitelist Escape as well.

Sincerely, I don't know what this call is actually doing. Removing it doesn't affect the tests in DatePicker.

@web-padawan
Copy link
Member

I would suggest to also add an integration test e.g. dialog-grid.test.js similar to dialog-date-picker.test.js.

@DiegoCardoso
Copy link
Contributor Author

I would suggest to also add an integration test e.g. dialog-grid.test.js similar to dialog-date-picker.test.js.

Done.

Copy link
Member

@web-padawan web-padawan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Improved the test to use sendKeys() which we usually do for integration tests.

@sonarqubecloud
Copy link

@web-padawan web-padawan merged commit b514373 into main Oct 23, 2025
9 checks passed
@web-padawan web-padawan deleted the fix/overlay/check-keydown-event branch October 23, 2025 07:49
DiegoCardoso added a commit that referenced this pull request Oct 23, 2025
…) (#10364)

Co-authored-by: Diego Cardoso <diego@vaadin.com>
DiegoCardoso added a commit that referenced this pull request Oct 23, 2025
…) (#10365)

Co-authored-by: Diego Cardoso <diego@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dialog with Grid closes on escape when interacting with cell

5 participants