-
Notifications
You must be signed in to change notification settings - Fork 841
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
[EuiContextMenu] Fix tab keypress requiring two presses to work correctly #5719
Conversation
setTimeout(() => { | ||
// NOTE: document.activeElement is stale if not wrapped in a setTimeout | ||
const focusedItemIndex = this.state.menuItems.indexOf( | ||
document.activeElement as HTMLElement | ||
); | ||
|
||
// We need to sync up with the user if s/he is tabbing through the items. | ||
this.setState({ | ||
focusedItemIndex: | ||
focusedItemIndex >= 0 && | ||
focusedItemIndex < this.state.menuItems.length | ||
? focusedItemIndex | ||
: undefined, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly just indentation changes due to the setTimeout wrapper, so I recommend viewing the diff with whitespace changes hidden. I moved comments around a little bit as well but otherwise that was it
- removing user gender - removing 'if' statement - since I moved the comment location, it makes less sense
Co-authored-by: Chandler Prall <[email protected]>
Preview documentation changes for this PR: https://eui.elastic.co/pr_5719/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5719/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know (now...) that FF doesn't tab to links, but I think we'd need to 'correct' that behaviour when the menu item is a link. That likely means not relying on the browser to find the next element but interrupting the tab behaviour with a call to tabbable to get the next element and manually That's a bigger ask than the original issue itself called for, and the WAI guidelines for menus/menubars says
and their examples (navigation, editor) show that pressing So I was curious about other menus/menu bars. Mac app menu: tab advances to the next menubar item Seems like some wiggle room or our own interpretation, but doesn't feel like that includes tabbing between menu items. My hope was that we could have a quick fix to the double-tab bug before re-evaluating the context menu's a11y conformance, but FF's link+tab handling might be a wrench in that plan. |
I wonder if this is a Mac-specific...feature?... I found an MDN thread that Firefox can follow the MacOS system prefs for focus handling if not set in the browser itself. I generally change my system prefs immediately on a new box, so I've never noticed Firefox doesn't focus links by default. Found this article on the Web Archive from MDN that might alleviate the issue Chandler is seeing: http://web.archive.org/web/20201112003144/https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference/accessibility.tabfocus |
I agree with you @constancecchen we shouldn't be hijacking native tab focus behavior. I'm just looking for reasons why links might not be receiving focus as expected. |
It's because FF and Safari are respecting the checkbox in the Mac OS system setting that I highlighted above. Once you check it FF and Safari will tab to links. |
100% agree we shouldn't change a user's expected behaviour. Links in context menus don't visually look like links, and I think it would be confusing why tab would skip an item seemingly "at random". That, together with the WAI recommendation of an altogether different tab behaviour, is has me hesitant on merging this as-is or putting more effort into an alternate solution. @1Copenut do you have thoughts on the WAI conformance here? Is it worth patching the tab behaviour this component used to have:
|
It doesn't have to be an either-or, we can merge this in and get a nice quality of life fix in for Windows/Chrome keyboard users in the interim while we create a follow-up issue for larger accessibility/WAI-ARIA fixes. |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5719/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Constance pointed out over zoom that MacOS FF+Safari users are already affected by the skip-a-link 'functionality' in the context menu, and I definitely missed that!
This is a QOL improvement and we'll revist the WAI issues as a separate thing.
I'll give Chandler's comment a look tomorrow and open an issue if needed. |
After taking a longer look at our EuiContextMenu and the WAI guidelines for menus and menubars, I have some better guidance. True menus and menubars behave like OS menus, which is a subtle but important distinction:
This is where it's open to interpretation, but reading the spec a second and third time, it sounds like this pattern expects a
This pattern holds up as a composable child for the larger |
Summary
closes #1101
closes #5239
What was happening was that
document.activeElement
was stale/looking at the previously focused element (before the tab event) and focus was moving forward (on tab) and then immediately backwards to the previously focused element whenthis.setState({ focusedItemIndex })
was called, hence the 2 key presses bug.Wrapping the entire thing in a
requestAnimationFrame
removes the stale factor and everything works on all latest evergreen browsers.Checklist