Enter key to select Item in Grid - Vaadin 24

Hi All,

In Vaadin 24 grid, I want to add the Enter key as shortcut to select the row in grid.

Is it possible?

Best Regards,
Amal

I assume you want to select the item is currently focused after moving the cell focus with the keyboard arrow keys for example.

In that case something like this should work:

grid.addCellFocusListener(focusEvent -> {
    var focusedItem = focusEvent.getItem().orElse(null);
    // store focused item somewhere
});

Shortcuts.addShortcutListener(this, event -> {
    var focusedItem = // retrieve focused item
    grid.select(focusedItem);
}, Key.ENTER).listenOn(grid);

It worked, Thank you :slightly_smiling_face: