Skip to content

Escape as a click shortcut close the dialog when an overlay is opened #8252

@jcgueriaud1

Description

@jcgueriaud1

Description

When I open an overlay in a dialog and press Escape it closes the overlay, not the dialog.
If I add a button in the dialog with button.addClickShortcut(Key.ESCAPE); then sometimes it closes the overlay only, sometimes the dialog and the overlay.

  • DatePicker: close both
  • TimePicker: close only the overlay
  • Popover: in Vaadin 24.8 closes only the overlay. In Vaadin 24.9 closes both
  • Select: close both
  • Combobox: close only the overlay

Expected outcome

  • first Esc press should close the overlay
  • the second one should close the dialog

ComboBox / TimePicker work as expected, likely because they call stopPropagation() for the keydown event

Popover: in Vaadin 24.8 closes only the overlay. In Vaadin 24.9 closes both

Sounds like a regression from the recent change to use global listeners.

Minimal reproducible example

@Route("dialog-demo")
@PageTitle("Dialog Demo")
@Menu(order = 1, icon = "vaadin:list-select", title = "Dialog Demo")
class DialogDemoView extends Main {

    DialogDemoView() {
        setSizeFull();
        var combo = new MultiSelectComboBox<String>("Select items");

        combo.setItems("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6");
        add(new ViewToolbar("MultiSelect Demo"));
        add(combo);

        Dialog dialog = new Dialog();
        dialog.setCloseOnEsc(true);

        TextField field = new TextField("Search date range");
        field.setWidth("340px");
        Icon icon = LumoIcon.DROPDOWN.create();
        field.setSuffixComponent(icon);

        var popover = new Popover();
        popover.setCloseOnEsc(true);
        popover.setWidth("340px");
        popover.setAriaLabel("Select a date range");
        popover.setTarget(field);
        popover.add(new Span("Dummy data"));

        Shortcuts.addShortcutListener(field, popover::open, Key.ARROW_DOWN)
                .listenOn(field);

        Select<String> select = new Select<>();
        select.setItems("Item 1", "Item 2", "Item 3", "Item 4", "Item 5");
        dialog.setModal(false);
        Button button = new Button("Close", e -> dialog.close());
        button.addClickShortcut(Key.ESCAPE);
        dialog.add(combo,
                new DateTimePicker(),
                new DatePicker(),
                field, select, button
        );
        dialog.open();
        add(dialog, new Button("open", e -> dialog.open()));
    }
}

Steps to reproduce

  • Open the dialog
  • Open an overlay
  • Press Escape

Environment

Vaadin version(s): 24.9.4

Browsers

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions