Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseFocus::validate_globalkeydown only validates if keyboard focused. #883

Open
Tropix126 opened this issue Sep 14, 2024 · 1 comment
Open
Assignees

Comments

@Tropix126
Copy link
Contributor

Tropix126 commented Sep 14, 2024

This is probably intended behavior, but it's not consistent with what other platforms do. The code in question:

e.data.code == Code::Enter && self.is_selected()

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.

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, 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
@Tropix126 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
@marc2332 marc2332 self-assigned this Sep 14, 2024
@marc2332
Copy link
Owner

marc2332 commented 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants