Skip to content

Adding click shortcut for ENTER key on button will fire the click event twice when the button is focused, even when disallowing browser default #14187

Closed
vaadin/web-components
#6404

Description

@willemv

Description of the bug

When I

  • add a click shortcut for the Key.ENTER key on a button, and
  • set browser default allowed to false on that shortcut registration, and
  • then press enter while the Button is focused

The click listener attached to the button will fire twice.

A closely related issue is reported in #8037, where the advice was to call setBrowserDefaultAllowed(false) on the shortcut registration.

However, as reported here, even when I follow that advice, I still get the double event handling.

Expected behavior

The click listener should only be called once.

Minimal reproducible example

AtomicInteger counter = new AtomicInteger(0);
Button counterButton = new Button("Testing", click -> {
    Notification.show("Count: " + counter.incrementAndGet());
});
ShortcutRegistration shortcutRegistration = counterButton.addClickShortcut(Key.ENTER);
shortcutRegistration.setBrowserDefaultAllowed(false);
// shortcutRegistration.setEventPropagationAllowed(false); // I tried with this as well, didn't make a difference
add(counterButton);

Versions

  • Vaadin / Flow version: 23.1.3
  • Java version: 11.0.13
  • OS version: Linux
  • Browser version (if applicable): Firefox 102.0.1

Activity

  1. mcollovati commented on Jul 22, 2022

    @mcollovati
    Collaborator

    Seems like that on the server side we always receive two separated events: a click triggered by button because of pressing Enter key and the key down event.

    Similar to #14190

  2. web-padawan commented on Mar 2, 2023

    @web-padawan
    Member

    This was again reported at vaadin/flow-components#4757. Here's a recording from that issue:

    button-double-click

  3. circlesmiler commented on Dec 13, 2023

    @circlesmiler

    @web-padawan @TatuLund How can vaadin/web-components#6404 fix this bug?

    When you use ENTER as the shortcut key, it's still the same. As far as I understand, the bugfix only works if you use a modifier key in combination with ENTER for the shortcut key? If you only use ENTER like in this example, the described misbehaviour is still there, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions