'Enable Enter key like Tab Key in Vaadin Flow
I would like to use enter key in my input component like the tab key in Vaadin 14.
How can I do this for all application?
I tried something like this, but some inputs don't work very well:
ShortcutEventListener listenerEnter = event -> {
System.out.println(" ->->->->->->->->->->->->->->->->->->->->-> listenerEnter");
UI.getCurrent().getPage().executeJs( "const element = document.activeElement;"+
"var universe = document.querySelectorAll('input, select, textarea, VAADIN-TEXT-FIELD');"+
"var list = Array.prototype.filter.call(universe, function(item) {return item.tabIndex >= '0'});"+
"var index = list.indexOf(element);"+
"var nextEl = list[index + 1] || list[0];"+
"nextEl.focus();"
);
};
UI.getCurrent().addShortcutListener(listenerEnter, Key.ENTER);
And how can I disable this behavior for one specific input? Some times we need to execute some action when the user presses Enter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
