How to Prevent/Disable ESCAPE Key shortcut on Sub Windows

Hi

I create a
com.vaadin.ui.Window
and add it via:
UI.getCurrent().addWindow(myWindow)
;

When pressing
and releasing
the ESCAPE key on my keyboard, the window automatically closes

Is there any way to disable this feature?


This issue actualluy creates a pretty severe bug on my app:

  1. User opens a sub-window with a form containing many fields to fill
  2. While filling the form, User chooses to upload a file
  3. The Native OS’s File Dialog shows on screen
  4. User regrests file upload, closing the dialog with
    the ESCAPE button
  5. ESCAPE
    press
    - the File Dialog closes (OS behavior)
  6. ESCAPE
    release -
    the Vaadin Sub Window closes, and all of the form data is lost…

I don’t expect Vaadin to fix this issue so quickly - but just give us an easy option to disable ESCAPE on a specific sub-window


And more important:
[color=#FF0000]


Document this issue in ‘Book of Vaadin’

[b]

[/b]
[/color]- for future developers.

Thanks,

Eyal

Anyone from the Vaadin Team, please reply on this

It gets even more nasty:

  1. Open any Menu (MenuBar, ComboBox, NativeSelect, ContextMenu, etc)
  2. Press (and release) the ESCAPE key to close the menu [size=4]
  3. The menu is closed,
    and so is your window (!)
    , with all the information you just entered in its form

This is really something that should be addressed…

Just provide API to either disable the shortcut, or make it smart enough to detect that the ESCAPE just closed a menu
[/size]

The same issue affects com.vaadin.ui.ComboBox placed on a subwindow,
closing opened combobox by ESC key closes the subwindow.

Any progress finding a workaround?

Hi,

Good catch. Previously, you would have needed to call setCloseShortcut() to set a close shortcut and call removeCloseShortcut() to remove it.

I dug around a bit in the code, and found that a ESC had been hard-coded to close the window as part of adding WAI-ARIA support. I filed a ticket for this here http://dev.vaadin.com/ticket/17383

Please see the ticket for updates on progress.

As this is hardcoded in the client code, the only way you could get around it is to replace the VWindow implementation with your own fixed one and recompiling.

I don’t know if this issue is allready resolved, but possible workaround (version 7.3.8) works for me:

public class EscSafeWindow extends Window
{
    public EscSafeWindow()
    {
        setClosable(false);

        Button closeButton = new Button("Close");
        closeButton.addClickListener(event -> {
            setClosable(true);
            close();
        });
        closeButton.setVisible(false);

        setContent(new CssLayout(closeButton));

        addShortcutListener(new CloseShortcut(this, KeyCode.ESCAPE));
    }
}