ClickShortcut does not behave like the click itself

I have a simple View with a TextField and a Button

@Route
public class MainView extends VerticalLayout {

    public MainView() {
        TextField textField = new TextField();
        add(textField);

        Button button = new Button("Click me");
        ShortcutRegistration shortcutRegistration = button.addClickShortcut(Key.F8);
        shortcutRegistration.setBrowserDefaultAllowed(false);
        shortcutRegistration.setEventPropagationAllowed(true);
        button.addClickListener(event -> {
            System.out.println("Value: " + textField.getValue());
        });

        add(button);
    }

}

When I click the Button then I get the value of the TextField but when I hit F8 the value is empty.

Is this a bug or am I missing something?

Works as designed.

The value is empty due to the shortcutRegistration.setBrowserDefaultAllowed(false) call - this prevents the textfield value to be synchronized to the server side.

You have couple options

remove the setBrowserDefaultAllowed(false);, you should anyway use a safe shortcut for the users that doesn’t map to any other shortcut like a browser or OS default shortcut

set the text field value change mode to EAGER, or starting from Vaadin14 (Flow 1.5 and never TextField) it could be LAZY or TIMEOUT (I haven’t tested this, but presume it should work)

From https://github.com/vaadin/flow/issues/5410#issuecomment-479515671