-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(Tooltip): prevent focus hijacking by other tooltips with focus trap #8713
fix(Tooltip): prevent focus hijacking by other tooltips with focus trap #8713
Conversation
Deploy preview for carbon-elements ready! Built with commit 7c140b7 |
Deploy preview for carbon-components-react ready! Built with commit 7c140b7 https://deploy-preview-8713--carbon-components-react.netlify.app |
✔️ Deploy Preview for carbon-elements ready! 🔨 Explore the source changes: c199ae6 🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-elements/deploys/60b5233e6643880008984fed 😎 Browse the preview: https://deploy-preview-8713--carbon-elements.netlify.app |
✔️ Deploy Preview for carbon-components-react ready! 🔨 Explore the source changes: c199ae6 🔍 Inspect the deploy log: https://app.netlify.com/sites/carbon-components-react/deploys/60b5233ef682250008979680 😎 Browse the preview: https://deploy-preview-8713--carbon-components-react.netlify.app/iframe |
only occurs if focus is not applied to another element after blur
7c140b7
to
1644a75
Compare
It's working fine with mouse, but ran into an issue on keyboard, that if I tab into a non interactive tooltip then tab somewhere else, it stays open, even if I open another tooltip. With the interactive tooltip, I couldn't tab out of it bc it had the focus trap, so I had to press esc, which then closed both of the tooltips. Screen.Recording.2021-05-18.at.2.34.55.PM.mov |
this is the existing behavior and I believe also the expected behavior. these tooltips are more like toggletips in that they require explicit dismissal (as they are referred to as "interactive tooltips"), so the tooltip with no focusable children needs an explicit Esc keypress or clicking on a non-child element to dismiss it (as opposed to the definition and icon tooltips which will dismiss on blur) |
I'm not sure I would call that the expected behavior. I think if it doesn't have interactive children, it behaves more like an icon tooltip or definition tooltip, whose expected behavior is to be shown on hover and focus. I would expect the non interactive one to close when tabbing to another element since it no longer has focus. |
I think if it's expected to work more like a toggle tooltip, then we need to add some sort of logic so that if the focus is on the "toggle" button, and the tooltip is shown, then you can't tab out of it until you press |
cc: @dakahn any thoughts? (see comments above) |
I was referring to the behavior for the interactive tooltip above ("They persist [sic] until intentionally dismissed by clicking outside of the tooltip") which is meant to be different from the icon tooltip (remember the interactive tooltip's trigger doesn't require an icon) If the expected behavior should be revised in that regard, I think it can be revisited by the design team. but in any case, given that it is not a regression and is not the topic of the referenced issues, I believe its scope lies outside of the current PR |
Right. But if you're navigating via keyboard, you can't click outside of the tooltip. Moving focus is the equivalent of clicking outside of the tooltip for keyboard users, so shouldn't the non interactive one close? I thought the scope of this PR was to not have tooltips remain open if they lose focus (whether its via mouse or keyboard). |
this PR is resolving focus hijacking described in the referenced issues but it seems that you are describing keyboard navigation behavior which doesn't appear to be a regression WRT this PR or the referenced issues. on that topic, the dismissal action for keyboard users would be with Esc |
bump @jnm2377 when you have some time! |
…ap (carbon-design-system#8713) * fix(Tooltip): prevent focus hijacking with focusable children * fix(Tooltip): restore focus to trigger element only occurs if focus is not applied to another element after blur * docs(Tooltip): add temporary test story Co-authored-by: TJ Egan <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Closes #8653
related #7260
related #7319
#7260 reported focus hijacking when clicking from tooltip to tooltip and was resolved in #7319. However, this only addressed the use case where the tooltips contained no focusable children. Focus would be restored to a tooltip's trigger element on loss of focus and multiple tooltips with focus traps would conflict with each other, leading to situations where multiple tooltips could be open at once. The order of the focus events was different in Firefox, but this conflict of focus events occurred in all browsers. This PR updates tooltip focus logic so that pages with multiple tooltips (particularly ones with focusable children/focus traps) will not hijack focus from the already focused elements
Changelog
New
Changed
Testing / Reviewing
Verify that focus is applied to the expected elements when navigating pages with Carbon tooltips using the mouse or keyboard in all browsers, regardless of whether or not the tooltips contain focusable children