You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The is_selected check will only evaluate to true if a keyboard was used to focus the target element which isn't the expectation of what should happen (Enter/Space always click the focused element regardless of input method used to gain focus). This could especially be a problem if focus was triggered from a screenreader then Enter was pressed.
It's also worth noting that on the web/Qt in specific, Space/Enter keys have different behavior regarding focus. Space will only click the element on key up, while Enter will click it immediately on key down. Other UI toolkits (like GTK, which has both trigger on keyup) don't necessary follow this convention though.
Suggestions
validate_globalkeydown should return matches!(e.data.code, Code::Enter | Code::Space) && self.is_selected().
(maybe) is_selected could be renamed to is_keyboard_focused or something similar to be more clear to users, especially after a11y_selected will become an attribute.
(maybe) Upon receiving a key press (on any key) after being focused with the mouse, is_selected should return true and the element should be considered keyboard focused.
(maybe) Enter and Space should be handled differently in components, with Enter being onkeydown and Space being onkeyup
The text was updated successfully, but these errors were encountered:
Tropix126
changed the title
UseFocus::validate_globalkeydown only validates if keyboard focus is applied.UseFocus::validate_globalkeydown only validates if keyboard focused.
Sep 14, 2024
I accidentally renamed this from UseFocus::validate_keydown, now that keydown is a focus-powered event it makes me wonder if this function is even needed?
This is probably intended behavior, but it's not consistent with what other platforms do. The code in question:
freya/crates/hooks/src/use_focus.rs
Line 86 in 13f67c5
The
is_selected
check will only evaluate totrue
if a keyboard was used to focus the target element which isn't the expectation of what should happen (Enter
/Space
always click the focused element regardless of input method used to gain focus). This could especially be a problem if focus was triggered from a screenreader thenEnter
was pressed.Demonstrations on other toolkits
GTK behavior (mousedown to focus the element, pressing space/enter after):
https://github.com/user-attachments/assets/3d6ce4fd-6ac0-4fed-9e5d-e66ffc7cb75b
Chromium behavior (rougly same as GTK.
:focus-visible
implies focus originated from a keyboard input (Tab
or similar). Also worth noting that:focus-visible
is triggered after any key is pressed while focused with the mouse):https://github.com/user-attachments/assets/7dc05ed4-1055-4e2b-927f-28932a45d5ac
Qt (identical to Chromium)
https://github.com/user-attachments/assets/0b575790-d405-47dd-996c-1156be8280f7
It's also worth noting that on the web/Qt in specific,
Space
/Enter
keys have different behavior regarding focus.Space
will only click the element on key up, whileEnter
will click it immediately on key down. Other UI toolkits (like GTK, which has both trigger on keyup) don't necessary follow this convention though.Suggestions
validate_globalkeydown
should returnmatches!(e.data.code, Code::Enter | Code::Space) && self.is_selected()
.is_selected
could be renamed tois_keyboard_focused
or something similar to be more clear to users, especially aftera11y_selected
will become an attribute.is_selected
should return true and the element should be considered keyboard focused.Enter
andSpace
should be handled differently in components, withEnter
beingonkeydown
andSpace
beingonkeyup
The text was updated successfully, but these errors were encountered: