flow icon indicating copy to clipboard operation
flow copied to clipboard

Can't use focus shortcut key inside the field

Open yuriy-fix opened this issue 3 years ago • 1 comments

@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);

yuriy-fix avatar Sep 14 '21 10:09 yuriy-fix

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.

mshabarov avatar Sep 17 '21 12:09 mshabarov