flow
flow copied to clipboard
Can't use focus shortcut key inside the field
@heruan commented on Fri Sep 27 2019
TextField#addFocusShortcut
could be very useful to implement quick shortcut like GitHub's. For example, in GitHub just pressing S will focus the search bar. If I try to do this in Vaadin:
field.addFocusShortcut(Key.of("s"));
It works, but then I'm not able to write any s
into the field 😄
Also, if I push S when I'm in another field, it loses focus to select the one bound to the shortcut.
I guess GitHub handles this ignoring shortcuts when inside a typeable field. Is it possible to do this in Vaadin? I would expect something like:
var shortcut = field.addFocusShortcut(Key.of("s"));
shortcut.ignoreOnTypeableFields();
// or
shortcut.ignoreOn(HasValue.class);
shortcut.ignoreOnTypeableFields(); // or shortcut.ignoreOn(HasValue.class);
I'd consider to have both methods available in API.
shortcut.ignoreOn(HasValue.class);
is appropriate when the page hasn't that much components to be ignored on the page and their list is static, i.e. they are added only once during page construction and not changed.
But if a new HasValue
components are be added to the page dynamically, they won't be taken into account in the key down event filters inside shortcut
.