-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add new tooltip component to DS #2054
base: main
Are you sure you want to change the base?
Conversation
✅ Thanks for the improvements! Browse a preview of your changes using the link below.
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Amazing.
Proposing some tweaks to the content:
Intro
A tooltip provides short, descriptive information when a user hovers or focuses on an element. It contains helpful but non-critical information and is useful in a space-constrained user interface.
Guidelines
Be judicious in using tooltips and explore other design options that keep content visible before choosing to use a tooltip. Only consider using a tooltip for short, non-critical information in a space-constrained user interface. Because a tooltip is hidden until activated, ensure content within a tooltip is not essential for completing a task on the page. For more guidance, see the USWDS tooltip page.
Behavior
- Activate a tooltip by hovering or focusing on a help (question mark) icon situated next to text.
- Press the escape key to dismiss open tooltips.
- When a tooltip is at the edge of the user’s viewport, it should automatically reorient itself away from the edge of the screen to prevent content clipping.
Accessibility
As USWDS states, tooltips are progressive enhancements for the title
attribute and will display as the title
attribute if the component doesn’t initialize. When testing tooltips for accessibility, ensure they are compliant with USWDS tooltip accessibility tests.
72fde13
to
97188f9
Compare
@anselmbradford after trying a handful of techniques to conditionally load the tooltip third-party dependency only when a tooltip is used, I ultimately decided to not bundle the tooltip code with the rest of the DS and instead added it as a separate entrypoint using the |
packages/cfpb-design-system/src/components/cfpb-tooltips/tooltip.scss
Outdated
Show resolved
Hide resolved
packages/cfpb-design-system/src/components/cfpb-tooltips/index.js
Outdated
Show resolved
Hide resolved
When resolving conflicts, you'll want to delete the |
Should we have a cursor change on hover? |
If JS is off, it seems like the (?) icons should be hidden. |
I say no because a
I originally didn't do this because I figured there are scenarios where a user might want some words in the middle of a sentence to trigger a tooltip and it'd be bad if those words disappeared when JS is disabled. But our guidance explicitly states that help icons should trigger them so I'll add this feature and include a note about it in the guidance section. |
If you're hovered on the (?), the tooltip shows. If you then click the (?), the tooltip is dismissed—so that's the action I was thinking the cursor change would indicate. If not a cursor change, should there be a hover change on roll over? Or is that too button like? I noticed https://designsystem.digital.gov/components/tooltip/ has both a hover color change and a cursor change, but they also show the tooltip on buttons, so I'm unclear if that's completely covered by the buttons themselves, or if some of that is for the tooltip. Maybe @jenn-franklin can tell us how it should be and that's that. |
👍 to a cursor change + click to close. No hover change. Thanks for calling this out! |
b7d91b0
to
a6ff4d9
Compare
We have two cf.gov apps that use tooltips but limited documentation on best practices or how to use them in new projects. This PR adds one implementation to the DS. It requires a third party library called Tippy.js.
The `exports` field allows multiple entrypoints to be defined instead of just a single `main` entrypoint. This allows the bundled code to be selectively imported by developers. For our purposes, we can package the majority of our DS code into a single file but keep the tooltip code separate. Tooltips are used on very few pages and they rely on a third party library that we don't want users to unnecessarily download on every page of cf.gov. See https://nodejs.org/api/packages.html#package-entry-points
Just in case you missed it— |
We have two cf.gov apps that use tooltips but limited documentation on best practices or how to use them in new projects. This PR adds one implementation to the DS. It requires a third party library called Tippy.js.
It requires code in the following format:
Creating the CFPB theme requires augmenting the
tippy-* classes
. There's no CSS that's usable without the Tippy library so I didn't create ano-tooltip
organism.Testing
Screenshots
Notes
Todos
Checklist
Testing checklist
Browsers
Accessibility
Other