-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS - Tooltip: Make tooltip content hoverable #5919
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
Changes from all commits
f492137
2978e28
4f1e343
3a3e1af
87cf905
ced5066
6c34128
5d2dae0
afa116f
ae40ea7
adfdc0c
b530631
37422c4
32e113c
04124a3
39534b5
d4ca8c3
77a2769
04dcd6b
5bf3493
babcc2a
1cbd67f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
amyleadem marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,36 @@ | |
| // Variables | ||
| $triangle-size: 5px; | ||
|
|
||
| /// Create a spacer to increase target area for tooltip triangle. | ||
| /// | ||
| /// @param {String} $direction - The direction of the tooltip; can be top, bottom, left, right. | ||
| /// | ||
| /// @example | ||
| /// @include tooltip-spacer("top"); | ||
| /// | ||
| /// @output | ||
| /// .usa-tooltip__body--top::before { | ||
| /// top: 100%; | ||
| /// height: 5px; | ||
| /// left: 0; | ||
| /// right: 0; | ||
| /// } | ||
| @mixin tooltip-spacer($direction) { | ||
| &::before { | ||
| #{$direction}: 100%; | ||
|
|
||
| @if ($direction == "left") or ($direction == "right") { | ||
| bottom: 0; | ||
| top: 0; | ||
| width: $triangle-size; | ||
| } @else { | ||
| height: $triangle-size; | ||
| left: 0; | ||
| right: 0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* Tooltips */ | ||
| .usa-tooltip { | ||
| display: inline-block; | ||
|
|
@@ -28,19 +58,17 @@ $triangle-size: 5px; | |
| font-size: size("ui", $theme-tooltip-font-size); | ||
| opacity: 0; // Required for recalculating position. | ||
| padding: units(1); | ||
| pointer-events: none; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note We needed to remove the |
||
| width: auto; | ||
| white-space: pre; | ||
| z-index: 100000; | ||
| position: absolute; | ||
| /* positioning is completed with JS */ | ||
|
|
||
| &:after { | ||
| &::after { | ||
| content: ""; | ||
| display: block; | ||
| width: 0; | ||
| height: 0; | ||
| pointer-events: none; | ||
| border-left: $triangle-size solid transparent; | ||
| border-right: $triangle-size solid transparent; | ||
| border-top: $triangle-size solid color($theme-tooltip-background-color); | ||
|
|
@@ -49,6 +77,15 @@ $triangle-size: 5px; | |
| left: 50%; | ||
| margin-left: -$triangle-size; | ||
| } | ||
|
|
||
| // This pseudo element fills the gap between the tooltip trigger and body. | ||
| // Filling this gap allows the tooltip to stay open when the pointer moves | ||
| // from the tooltip trigger to the body. | ||
| &::before { | ||
| content: ""; | ||
| display: block; | ||
| position: absolute; | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| .usa-tooltip__body--wrap { | ||
|
|
@@ -66,8 +103,14 @@ $triangle-size: 5px; | |
| opacity: 1; | ||
| } | ||
|
|
||
| .usa-tooltip__body--top { | ||
| @include tooltip-spacer("top"); | ||
| } | ||
|
|
||
| .usa-tooltip__body--bottom { | ||
| &:after { | ||
| @include tooltip-spacer("bottom"); | ||
|
|
||
| &::after { | ||
| border-left: $triangle-size solid transparent; | ||
| border-right: $triangle-size solid transparent; | ||
| border-bottom: $triangle-size solid color($theme-tooltip-background-color); | ||
|
|
@@ -78,7 +121,9 @@ $triangle-size: 5px; | |
| } | ||
|
|
||
| .usa-tooltip__body--right { | ||
| &:after { | ||
| @include tooltip-spacer("right"); | ||
|
|
||
| &::after { | ||
| border-top: $triangle-size solid transparent; | ||
| border-bottom: $triangle-size solid transparent; | ||
| border-right: $triangle-size solid color($theme-tooltip-background-color); | ||
|
|
@@ -92,7 +137,9 @@ $triangle-size: 5px; | |
| } | ||
|
|
||
| .usa-tooltip__body--left { | ||
| &:after { | ||
| @include tooltip-spacer("left"); | ||
|
|
||
| &::after { | ||
| border-top: $triangle-size solid transparent; | ||
| border-bottom: $triangle-size solid transparent; | ||
| border-left: $triangle-size solid color($theme-tooltip-background-color); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <div class="usa-prose measure-5 padding-2 border-1px border-gray-20 margin-bottom-4"> | ||
| <p class="font-body-lg text-bold margin-top-0">Test that mouse event listeners target the correct tooltip when no parent wrapper is present</p> | ||
| <p>To test this, confirm that mouseover/mouseleave events work as expected when there is no parent wrapper on `usa-tooltip` elements.</p> | ||
| </div> | ||
|
|
||
| <h2>Tooltip with no wrapper</h2> | ||
|
|
||
| <button type="button" class="usa-button usa-tooltip" data-position="left" title="Show on left">Show on left</button> | ||
|
|
||
| <h2>Another tooltip with no wrapper</h2> | ||
|
|
||
| <a href="#" class="usa-tooltip" data-position="bottom" title="Show on bottom">Show on bottom</button> |
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:
usa-tooltipwrapper instead of the tooltip trigger, andmouseoutwithmouseleave.mouseleaveonly triggers when the mouse has exited the element and all its descendents, whereasmouseouttriggers 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
https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseleave_event ↩