Dialog does not reveice key events.
See original GitHub issueI want to implement a simple confirm dialog with a primary button, that is clicked, when the user press the enter key. For that I extended the class Dialog, implement KeyNotifier and add a listener for the key down event.
The listener is never called.
I tried the same with getElement().addEventListener("keydown", ...)
, same result, nothing happens.
The following code is somehow a workaround for the dialog.
public class DialogImpl extends Dialog {
private void init() {
// ...
getElement().getNode().runWhenAttached(ui -> {
DomListenerRegistration keydown = ui.getElement().addEventListener("keydown", event -> finalSelectedPrimaryButton.click());
addDetachListener(event -> {
keydown.remove();
});
});
}
}
Nevertheless, it should work somehow easier to react with a dialog on key events.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Enter Key Event Is Not Working On Dialog In Javafx?
Normally, a button with focus will fire when you press space , not enter . There are however special buttons that will activate...
Read more >Dialog keypress events - MSDN - Microsoft
There are two key press events which produce a similar result. By default when a dialog is created, the ENTER and ESCAPE keys...
Read more >Keyboard: keydown and keyup - The Modern JavaScript Tutorial
The keydown events happens when a key is pressed down, and then keyup – when it's released. event.code and event.key. The key property...
Read more >KeyEvent - Android Developers
You should never rely on receiving KeyEvents for any key on a soft input method. ... If the key code is not KEYCODE_UNKNOWN...
Read more >Handling Events :: Eloquent JavaScript
The DOM node where a key event originates depends on the element that has focus when the key is pressed. Most nodes cannot...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Legioth thanks for the information, it seems to work.
My code:
ComponentUtil.addListener(UI.getCurrent(), KeyDownEvent.class, event -> System.out.println("KeyDown"))
This returns a
Registration
, which needs to beremove
d inonDetach
Since Vaadin 14.5 this is fixed for
Shortcuts
when they target aDialog
component.