-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add an accessible tooltip mechanism, and use it for the "Remember Me" login tooltip ( #55343 & #51006 ) #12212
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
Closed
rutviksavsani
wants to merge
25
commits into
WordPress:trunk
from
rutviksavsani:add/accessible-tooltip-remember-me
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c8e9abe
General: Introduce wp_get_tooltip() for accessible tooltips.
rutviksavsani 769355f
Login and Registration: Add a tooltip to the "Remember Me" field.
rutviksavsani e157366
Merge branch 'trunk' into add/accessible-tooltip-remember-me
rutviksavsani c42b3c9
Merge branch 'trunk' into add/accessible-tooltip-remember-me
rutviksavsani c48a20b
Merge branch 'trunk' into add/accessible-tooltip-remember-me
rutviksavsani 5dd6257
Merge branch 'trunk' into pr/12212
joedolson d2dc544
Update tooltip implementation
joedolson 529f4e6
Update tests
joedolson a1f4ef1
Update wpGetTooltip.php
joedolson 391b195
Test needs to address changed classes.
joedolson fff1b3c
Change default label to match icon; enforce tooltip behavior
joedolson 877afb9
Update wp-tooltip.js
joedolson 0cf4b5a
Now that tooltips only render the content, remove description
joedolson 99648d3
Improve docs
joedolson 26716f1
Update styles; restore login example for testing.
joedolson c8473cc
Merge branch 'trunk' into add/accessible-tooltip-remember-me
joedolson 80d2b00
Update tests
joedolson f2a36e5
Remove test instance.
joedolson 9735888
Switch to helper function with two callers
joedolson 57720a9
Update general-template.php
joedolson 784617f
Update tests to call appropriate functions
joedolson f53e5e2
Ugh
joedolson f7e543a
wp_get_tooltip() should not require second arg
joedolson bf92ddc
Sheesh.
joedolson 5db8a20
type arg no longer required.
joedolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * @output wp-admin/js/wp-tooltip.js | ||
| */ | ||
|
|
||
| /** | ||
| * Add focus and hover support for the 'tooltip' type in `wp_tooltip()`. | ||
| * This script can be made obsolete when support is available for Interest Invokers. | ||
| */ | ||
| (() => { | ||
|
|
||
| const popovers = document.querySelectorAll( '.wp-is-tooltip' ); | ||
| let openTimeout; | ||
|
|
||
| popovers.forEach( function( popover ) { | ||
| let trigger = popover.querySelector( 'button.wp-tooltip__toggle' ); | ||
| let panel = popover.querySelector( 'span.wp-tooltip__bubble' ); | ||
|
|
||
| // Show Tooltip Function (with delay to prevent flickering). | ||
| const showTooltip = () => { | ||
| clearTimeout( openTimeout ); | ||
| openTimeout = setTimeout( () => { | ||
| // Only show if it's not already open. | ||
| if ( ! panel.matches( ':popover-open' ) ) { | ||
| // pass the triggering element so implicit position anchors work. | ||
| panel.showPopover( { source: trigger } ); | ||
| } | ||
| }, 300 ); | ||
| }; | ||
| // Hide Tooltip Function. | ||
| const hideTooltip = () => { | ||
| clearTimeout( openTimeout ); | ||
| if ( panel.matches( ':popover-open' ) ) { | ||
| panel.hidePopover(); | ||
| } | ||
| }; | ||
|
|
||
| // Bind Hover and Focus Events. | ||
| trigger.addEventListener( 'mouseenter', showTooltip ); | ||
| trigger.addEventListener( 'focus', showTooltip ); | ||
|
|
||
| trigger.addEventListener( 'mouseleave', hideTooltip ); | ||
| trigger.addEventListener( 'blur', hideTooltip ); | ||
| }); | ||
| })(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* Accessible tooltip component. Markup from wp_get_tooltip(). */ | ||
|
|
||
| .wp-tooltip { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| vertical-align: middle; | ||
| } | ||
|
|
||
| /* Toggle and close buttons. */ | ||
| .wp-tooltip .wp-tooltip__toggle, | ||
| .wp-tooltip .wp-tooltip__close { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 24px; | ||
| height: 24px; | ||
| padding: 0; | ||
| border: 0; | ||
| border-radius: 2px; | ||
| background: none; | ||
| color: #50575e; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .wp-tooltip .wp-tooltip__toggle:hover, | ||
| .wp-tooltip .wp-tooltip__toggle:focus, | ||
| .wp-tooltip .wp-tooltip__close:hover, | ||
| .wp-tooltip .wp-tooltip__close:focus { | ||
| color: var(--wp-admin-theme-color, #3858e9); | ||
| } | ||
|
|
||
| .wp-tooltip .wp-tooltip__toggle:focus, | ||
| .wp-tooltip .wp-tooltip__close:focus { | ||
| outline: 2px solid transparent; | ||
| box-shadow: 0 0 0 var(--wp-admin-border-width-focus, 1.5px) var(--wp-admin-theme-color, #3858e9); | ||
| } | ||
|
|
||
| .wp-tooltip .wp-tooltip__toggle .dashicons { | ||
| width: 20px; | ||
| height: 20px; | ||
| font-size: 20px; | ||
| } | ||
|
|
||
| .wp-tooltip .wp-tooltip__close .dashicons { | ||
| width: 18px; | ||
| height: 18px; | ||
| font-size: 18px; | ||
| } | ||
|
|
||
| /* Bubble. No position here, so it falls back to the UA's centered popover without anchoring. */ | ||
| .wp-tooltip .wp-tooltip__bubble { | ||
| max-width: min(280px, calc(100vw - 32px)); | ||
| margin: auto; | ||
| padding: 12px 16px; | ||
| overflow: visible; | ||
| border: 1px solid #c3c4c7; | ||
| border-radius: 4px; | ||
| background: #fff; | ||
| color: #1d2327; | ||
| font-size: 13px; | ||
| font-weight: 400; | ||
| line-height: 1.5; | ||
| text-align: left; | ||
| box-shadow: 0 3px 6px rgba(0, 0, 0, 0.08); | ||
| } | ||
|
|
||
| .wp-tooltip.wp-is-tooltip .wp-tooltip__bubble { | ||
| background: #000; | ||
| color: #f0f0f0; | ||
| text-align: center; | ||
| padding: 4px 8px; | ||
| line-height: 1.4; | ||
| } | ||
|
|
||
| .wp-tooltip:not(.wp-is-tooltip) .wp-tooltip__text { | ||
| display: block; | ||
| padding-inline-end: 24px; | ||
| } | ||
|
|
||
| .wp-tooltip .wp-tooltip__close { | ||
| position: absolute; | ||
| top: 6px; | ||
| inset-inline-end: 6px; | ||
| } | ||
|
|
||
| /* Anchor the bubble above its toggle, with a downward arrow. */ | ||
| @supports (anchor-name: --a) { | ||
| .wp-tooltip .wp-tooltip__bubble { | ||
| position-area: top; | ||
| margin: 0 0 8px; | ||
| position-try-fallbacks: flip-block, flip-inline; | ||
| } | ||
|
|
||
| .wp-tooltip.wp-is-tooltip .wp-tooltip__bubble { | ||
| margin: 0; | ||
| } | ||
|
|
||
| /* Arrow: gray border (::before) under a white fill (::after). */ | ||
| .wp-tooltip:not(.wp-is-tooltip) .wp-tooltip__bubble::before, | ||
| .wp-tooltip:not(.wp-is-tooltip) .wp-tooltip__bubble::after { | ||
| content: ""; | ||
| position: absolute; | ||
| top: 100%; | ||
| left: 50%; | ||
| width: 0; | ||
| height: 0; | ||
| border: 8px solid transparent; | ||
| border-bottom: 0; | ||
| } | ||
|
|
||
| .wp-tooltip:not(.wp-is-tooltip) .wp-tooltip__bubble::before { | ||
| margin-left: -8px; | ||
| border-top-color: #c3c4c7; | ||
| } | ||
|
|
||
| .wp-tooltip:not(.wp-is-tooltip) .wp-tooltip__bubble::after { | ||
| margin-left: -7px; | ||
| border-width: 7px; | ||
| border-bottom: 0; | ||
| border-top-color: #fff; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When it's a 'tooltip' it is still clickable, as in: hover and focus will reveal the tooltip. Pressing Enter / Spacebar or clicking it will toggle the tooltip. Maybe we should consider to prevent the click when it's a tooltip but this can be refined later after considering the desired behavior.
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.
Agree that this is best resolved later. I can see an argument for the click action still being supported. E.g.,
tabto focus, then hitescto hide the popup, then want to see what the accessible name of the control is, because you've forgotten.