flow
flow copied to clipboard
Can't listen for colon
Description of the bug
Listen on grid to press colon did not work there is no Key.COLON and even key.of(":") will not work.
Expected behavior
Get a event on pressing ":"
Minimal reproducible example
ui().addShortcutListener((event) -> doSomething() , Key.of(":")).listenOn(component);
Versions
- Vaadin / Flow version: 24.3.9
- Java version: 21.0.2
- OS version: Macos
- Browser version (if applicable): Chrome
- Application Server (if applicable):
- IDE (if applicable):
Colon is not listed in the keycode values (https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values). So, this is probably the reason why there's no enumeration entry.
I think the problem here is that the colon key is often shared with another key, and you have to press also a modifier (for example SHIFT). On my keyboard layout, I have colon and period sharing the same button; to output a colon, I have to press SHIFT.
So, back to your code, I can make it work by activating also SHIFT on the shortcut, for example
ui().addShortcutListener((event) -> doSomething() , Key.of(":"))
.withShift()
.listenOn(component);
This looks like a workaround, but I currently don't know if we can do something on Flow to better handle these special cases.
Key.of(":") is not working also.
ui().addShortcutListener((event) -> panel.focusResources() , Key.of(":")).listenOn(resourcesGrid);
no reaction for the key, but
ui().addShortcutListener((event) -> panel.focusResources() , Key.SEMICOLON).listenOn(resourcesGrid);
is fine.
Did you also try with withShift()?
ui().addShortcutListener((event) -> panel.focusResources() , Key.of(":")).withShift().listenOn(resourcesGrid);
is working (!). Is it working on every keyboard layout?! Hopefully.