You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Click shortcut of focused vaadin button triggers with key modifiers #14190
In our vaadin application we are used to having several buttons within a form. Additionally we obviously have a button which triggers the save functionality. For the save button we registered a click shortcut consisting of the enter key and the control key. Now the problem: If one of the several buttons is focused and the user hits the control key + the enter key, first the action of the focused button triggers and afterwards the form gets saved.
Yes, this is an issue in Flow. The web component has some logic to fire click on Enter or Space keys.
This is expected, also it's how native <button> works, so we are not going to change this.
I'm going to transfer this to Flow repository, as it seems slightly different from #14187
It seems the issue relates to #14187
Flow is receiving two events: click from the focused button and the keydown.
Since firing click event on Enter or Space is the default behavior for button, I don't know at the moment how we can prevent the click listener to be invoked.
Need further investigation
If I click the button or focus it and press enter, the event gets printed, if I press ctrl+enter it doesn't.
So in my opinion, this is not a Flow issue but should be fixed in the webcomponent. The clicklistener should only be triggered if enter is pressed without modifiers.
So in my opinion, this is not a Flow issue but should be fixed in the webcomponent. The clicklistener should only be triggered if enter is pressed without modifiers.
@probert94 I tend to agree, the workarounds are not needed when using NativeButton instead of Button. So if we use that as reference.
@Route("shortcut2")
public class Shortcut2View extends Div {
public Shortcut2View() {
NativeButton button1 = new NativeButton("1");
NativeButton button2 = new NativeButton("2");
button1.addClickListener(e -> {
Notification.show("1 clicked");
});
button2.addClickListener(e -> {
Notification.show("2 clicked");
});
Shortcuts.addShortcutListener(this, e -> {
button2.getElement().executeJs("this.click();");
}, Key.ENTER, KeyModifier.SHIFT).listenOn(this);
add(button1, button2);
}
}
Activity
sissbruecker commentedon Jul 20, 2022
This is likely a Flow issue.
Possibly related: #14187, #8037
web-padawan commentedon Jul 20, 2022
Yes, this is an issue in Flow. The web component has some logic to fire
clickon Enter or Space keys.This is expected, also it's how native
<button>works, so we are not going to change this.I'm going to transfer this to Flow repository, as it seems slightly different from #14187
mcollovati commentedon Jul 22, 2022
It seems the issue relates to #14187
Flow is receiving two events:
clickfrom the focused button and thekeydown.Since firing
clickevent onEnterorSpaceis the default behavior for button, I don't know at the moment how we can prevent the click listener to be invoked.Need further investigation
probert94 commentedon Mar 13, 2023
I am facing the same issue in a Vaadin application.
I just tested it on an empty webpage with the following code:
If I click the button or focus it and press enter, the event gets printed, if I press ctrl+enter it doesn't.
So in my opinion, this is not a Flow issue but should be fixed in the webcomponent. The clicklistener should only be triggered if enter is pressed without modifiers.
mshabarov commentedon Aug 22, 2023
The issue was triaged and currently added to the backlog priority queue for further investigation.
TatuLund commentedon Aug 24, 2023
Workarounds:
TatuLund commentedon Aug 24, 2023
@probert94 I tend to agree, the workarounds are not needed when using NativeButton instead of Button. So if we use that as reference.