Skip to content

feat(tooltip): add toggletip support with click-to-toggle behavior#733

Draft
jgorfine-zendesk wants to merge 3 commits intomainfrom
jgorfine/toggletip-with-claude
Draft

feat(tooltip): add toggletip support with click-to-toggle behavior#733
jgorfine-zendesk wants to merge 3 commits intomainfrom
jgorfine/toggletip-with-claude

Conversation

@jgorfine-zendesk
Copy link
Copy Markdown
Contributor

@jgorfine-zendesk jgorfine-zendesk commented Apr 1, 2026

  • BREAKING CHANGE?

Description

This PR adds toggletip support to the tooltip container, providing click-to-toggle behavior that follows accessibility best practices. The implementation follows the pattern outlined in the Inclusive Toggletips section of Heydon Pickering's Inclusive Components pattern library.

Toggletips are distinct from tooltips: they open/close on click rather than hover/focus, making them suitable for content that needs to persist for reading.

Key features:

  • New isToggletip prop enables toggletip mode
  • Opens/closes on click, not hover/focus
  • Closes on outside clicks and Escape key
  • Uses role="status" for live region announcements
  • isAnnouncementReady flag controls content population for screen reader re-announcements
  • Comprehensive test coverage (300+ new test lines)
  • README documentation and Storybook demo included

Detail

The implementation adds an isToggletip boolean prop to useTooltip and TooltipContainer. When enabled:

  1. Click behavior: Opens on first click, stays open on subsequent clicks (triggers re-announcement)
  2. Closing: Closes on blur, outside clicks, or Escape key (with proper focus management)
  3. Accessibility: Uses role="status" instead of role="tooltip", no aria-describedby on trigger
  4. Re-announcement pattern: Clears and repopulates content after 100ms on re-click for screen readers

Files changed:

  • packages/tooltip/src/useTooltip.ts: Core toggletip logic
  • packages/tooltip/src/TooltipContainer.tsx: Prop type definitions
  • packages/tooltip/src/TooltipContainer.spec.tsx: Comprehensive test suite
  • packages/tooltip/README.md: Usage documentation
  • packages/tooltip/demo/~patterns/stories/ToggletipStory.tsx: Storybook demo

Checklist

  • 🌐 demo is up-to-date (npm start)
  • 💂‍♂️ includes new unit tests
  • ♿ tested for WCAG 2.1 AA compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

🤖 Built with Claude Code

jgorfine-zendesk and others added 3 commits March 30, 2026 14:35
Add isToggletip prop to useTooltip hook for click-based interaction,
essential for touch devices where hover doesn't exist. Toggletips use
role="status" for screen reader announcements and include outside click
detection, Escape key handling, and smart focus management.

Changes:
- Add isToggletip, window, and document props to IUseTooltipProps
- Add isAnnouncementReady to IUseTooltipReturnValue for SR re-announcements
- Add getDocument() helper for SSR-safe document access
- Add tooltipRef and isAnnouncementReady state to useTooltip hook
- Add handleEscapeKey() to close toggletip with smart focus restoration
- Add handleToggletipTriggerClick() to handle open/re-announcement logic
- Add outside click detection effect (closes on clicks outside trigger/tooltip)
- Add document-level Escape key detection effect
- Update getTriggerProps() with conditional toggletip behavior (click handler, no hover/focus, no aria-describedby)
- Update getTooltipProps() with conditional toggletip behavior (role="status", ref for outside click detection)
- Update TooltipContainer defaultProps to include isToggletip: false
- Update TooltipContainer propTypes to include isToggletip, window, and document
- Add 15 comprehensive toggletip tests (ARIA attributes, click interaction, re-announcement, blur, outside clicks, Escape key, SSR)
- Add toggletip usage documentation to README with examples and best practices

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add ToggletipStory.tsx showcasing toggletip click-to-toggle behavior
- Register Toggletip story in patterns.stories.tsx
- Demo includes visual styling and proper use of isAnnouncementReady

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…tests

Fix TS2322 errors in CircleCI where button type property was incompatible:
"Type 'string | undefined' is not assignable to type '"button" | "submit" | "reset" | undefined'."

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 95.709% (+0.04%) from 95.67%
when pulling 3c53655 on jgorfine/toggletip-with-claude
into 623d1c7 on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants