-
Notifications
You must be signed in to change notification settings - Fork 920
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
USWDS - Tooltip: Make tooltip content hoverable #5919
Conversation
- Mouseleave makes the tooltip hoverable - it lets us target usa-tooltip
- This enables the tooltip to be hoverable
- This prevents mouseleave from triggering in the empty space b/t tooltip and trigger
content: ""; | ||
display: block; | ||
position: absolute; | ||
} | ||
} |
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.
@@ -28,7 +28,6 @@ $triangle-size: 5px; | |||
font-size: size("ui", $theme-tooltip-font-size); | |||
opacity: 0; // Required for recalculating position. | |||
padding: units(1); | |||
pointer-events: none; |
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.
Note
We needed to remove the pointer-event
styles here because they were causing the tooltip to be removed from the usa-tooltip
hit boundary. This caused mouseleave
to be triggered when hovering over the tooltip.
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.
Note
To prevent the tooltip from closing when you move the mouse out of the tooltip trigger, we needed to:
- Target the
usa-tooltip
wrapper instead of the tooltip trigger, and - Replace
mouseout
withmouseleave
.mouseleave
only triggers when the mouse has exited the element and all its descendents, whereasmouseout
triggers with each element in the group. See reference below for more details:
"...mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element)." 1
Footnotes
@mejiaj and @mahoneycm, this still needs JSDoc comments and probably a unit test, but opening this review now so that we can start discussing if there are ways to write this code that better align with standards. |
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.
Thanks for taking this on.
I hope you don't mind I've edited the PR description. I've simplified the summary for clarification (now its clear we're adding support to the tooltip body). As well as adding a table with preview links to the before/after state for easier testing.
This new behavior means we'll have to re-think our current approach to showing/hiding the tooltip. Right now it's listening for any mouseover on the trigger. We should consider either:
- Toggling visibility on
TOOLTIP
, instead ofTOOLTIP_TRIGGER
. - Using
mouseleave
, but ensuring it's only added once and removed on teardown.
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.
Note
I added this test because I discovered that my original fixes had the mouse events targeting the wrong tooltips when there were multiple tooltips on the page and no wrappers around the tooltips. This might not be needed moving forward, but wanted to push it up to confirm the fix is still working. We can remove before merge if this test feels confusing.
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.
Good catch here! Glad to see it's still working if the component is built this way.
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.
Getting close! A couple small changes I wanted to run by you to make sure we're covering all bases.
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.
Good catch here! Glad to see it's still working if the component is built this way.
- will be added to #5919 instead
- Not needed for this PR; will be added in #5909
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.
Minor changes request to pseudoelement format & suggestion for JS. Otherwise LGTM.
packages/usa-tooltip/src/index.js
Outdated
wrapper.addEventListener("mouseleave", () => { | ||
hideToolTip(body); | ||
}); |
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.
Follows the same pattern in teardown line 400
.
wrapper.addEventListener("mouseleave", () => { | |
hideToolTip(body); | |
}); | |
wrapper.addEventListener("mouseleave", () => hideToolTip(body)); |
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.
Updated in d4ca8c3
@amycole501 and @alex-hull can you confirm that the tooltip now conforms with the "hoverable" criteria in WCAG 1.4.13? |
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 tested the hoverable action and yes, it is now able to be hovered over with a mouse and then when I move the mouse over the tooltip it does NOT disappear.
Sorry @amycole501, I accidentally re-requested your review, which cleared the green approval check 🤦 |
The `$triangle-size` variable isn't a parameter, so removed from SASSDoc comment.
USWDS - Tooltip: Create a mixin for the tooltip spacer
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.
Great work here! Functionality is working like a charm
Testing checklist
- Confirm that you move your mouse into the tooltip content without the tooltip closing
- Confirm that you can move your mouse into the small space between the tooltip and the tooltip trigger without the tooltip closing
- Confirm that the toolip closes when you leave the
.usa-tooltip
hit boundary - Confirm the code meets standards.
- Confirm the code is compatible with the solution in USWDS - Tooltip: Make tooltip dismissible with escape key #5909
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.
No issues found. Tested in Safari, Firefox, and Chromium.
Thanks for adding the tests.
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.
Very nice. Both features work together as expected
Summary
Updated the behavior of tooltip to allow hover over tooltip content. This allows the component to meet the "hoverable" standard outlined in WCAG 1.4.13.
Note
This issue is slated to be in the same release as #5909, which also edits the tooltip JavaScript. We should confirm there are no conflicts between the two PRs.
Breaking change
This is not a breaking change.
Related issue
Closes #5918
Related pull requests
Changelog PR
Preview link
Problem statement
Success Criterion 1.4.13 Content on Hover or Focus states that for tooltip content must be hoverable:
The tooltip component does not currently meet this criteria.
Solution
Updated the method for detecting how and when the mouse leaves the tooltip. These were the main changes to accomplish this:
usa-tooltip
wrapper, rather thanusa-tooltip__trigger
. This added theusa-tooltip__body
element to the hit target.mouseout
withmouseleave
. This allowed us to triggerhideTooltip
only when the mouse left all elements inside the wrapper, rather than triggering after it left each element.pointer-events: none;
style declaration. This allowedmouseleave
to includeusa-tooltip__body
in the hit target.Testing and review
.usa-tooltip
hit boundaryNote
There is a pre-existing issue with the social media icon tooltips in the tooltip test story.