feat(tooltips): add toggletip support#2136
Conversation
Add an isToggletip prop that switches Tooltip to click-to-toggle behavior backed by the container's toggletip API. The role="status" live region is applied to the always-mounted wrapper while the visible bubble is gated on isAnnouncementReady, preventing an empty-bubble flash on open. Add toggletip control to the Tooltip story and Toggletip, Toggletip-with-anchor, and info-toggletip patterns. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Temporarily depend on the @zendeskgarden/container-tooltip 2.2.3-alpha.1 tarball so CI can install it and build the Storybook preview for manual testing of the toggletip feature. TEMPORARY: once the react-containers PR merges and the container is published, remove the tarball and depend on the released @zendeskgarden/container-tooltip instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Drop prose comments that don't match the codebase's sparse commenting convention. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Cover the integration glue that lives in Tooltip: role="status" live region, aria-expanded/aria-controls passthrough on the trigger, the gated bubble that mounts only when open, and type/size styling in toggletip mode. Behavioral coverage (click, Escape, outside-click, re-announcement) stays in the container spec to avoid duplication. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| "dependencies": { | ||
| "@floating-ui/react-dom": "^2.0.0", | ||
| "@zendeskgarden/container-tooltip": "^2.2.0", | ||
| "@zendeskgarden/container-tooltip": "file:../../zendeskgarden-container-tooltip-2.2.3-alpha.1.tgz", |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Definitely. My understanding is that this is the typical way we test container changes before they're merged in. 🙂 👍
| ## Toggletip | ||
|
|
||
| Setting the `isToggletip` prop switches the `Tooltip` into a toggletip: it opens | ||
| and closes on click rather than hover/focus, dismisses on outside click or |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| ## Toggletip with interactive content | ||
|
|
||
| Because a toggletip is dismissed on click rather than blur, its content can |
There was a problem hiding this comment.
This demo's premise — interactive content that stays open while you interact, doesn't hold under a mouse click, given the bundled container's outside dismiss handler:
const clickedTrigger = triggerRef.current?.contains(target);
if (!clickedTrigger) { closeTooltip(0); } // never checks tooltipReftooltipRef is never consulted, so a mousedown on interactive content inside the toggletip counts as an outside click and dismisses it.
The Anchor here happens to look fine only because clicking a link is terminal (it navigates as it closes). Any non-navigational interactive content (input, copy button, toggle) will dismiss on mousedown. The outside handler should probably exclude tooltipRef.current?.contains(target). Fix is in the container, but this demo asserts the behavior, so we should probably fix that
There was a problem hiding this comment.
Hey @bmson, that's a totally fair point, and I appreciate you flagging it.
Reading all of that, my question is: can/should we try and restrict the kinds of children a toggletip bubble can have, so that it's not even possible to render interactive elements (especially non-navigational interactive content) inside of them? 🤔
I ask for a few reasons:
- Having interactive content inside of a toggletip sorta goes against the idea of what a toggletip is: "toggletips exist to reveal information balloons, and serve no other purpose." —Inclusive Components
- Live regions don’t handle rich text
- Live regions are not suitable for notifications with interactive elements
If we're being honest, even having links inside of toggletips is a bit of a stretch...but I've seen designs with tooltips + links, out in the wild, and I wanted to try and be accommodating. 👀
There was a problem hiding this comment.
Yea, I've seen us have links in the tooltip 😆
It's probably fine, since it's not really a regression.
I'll leave this one up to you as the expert on this subject.
Description
Adds toggletip support to the
Tooltipcomponent via a newisToggletipprop, backed by the toggletip API in@zendeskgarden/container-tooltip. When enabled, the tooltip switches from hover/focus behavior to click-to-toggle: it opens and closes on click, dismisses on outside click orEscape, and announces its content through arole="status"live region. The trigger must be a<button>element.Detail
isToggletipis threaded throughTooltipintouseTooltip. The render tree stays unified — the toggletip path applies the live-region props to the always-mounted wrapper and gates the visible bubble onisAnnouncementReady, while the tooltip path keeps its hover handlers on the bubble.Tooltipstory exposesisToggletipas a control (defaultfalse).[patterns]demos: Toggletip, Toggletip with anchor (interactive content), and Info toggletip (icon-onlyIconButtontrigger with an explicitaria-label).Checklist
npm start)?bedrock)