question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dialog does not reveice key events.

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
probert94commented, Jan 16, 2019

@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 be removed in onDetach

0reactions
plekucommented, May 19, 2021

Since Vaadin 14.5 this is fixed for Shortcuts when they target a Dialog component.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found