Skip to content

fix(tooltip): automatically generate aria-describedby for accessibility #816

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MatanShushan
Copy link
Contributor

The tooltip component now automatically generates and sets a unique aria-describedby attribute that references the tooltip content's ID. This eliminates the need for manual configuration and ensures proper screen reader compatibility.

Previously, users had to manually provide aria-describedby values, often incorrectly as shown in documentation examples. The component now follows Angular Material's approach by programmatically managing the ARIA relationship.

Closes #781

PR Checklist

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Which package are you modifying?

Primitives

  • accordion
  • alert
  • alert-dialog
  • aspect-ratio
  • avatar
  • badge
  • breadcrumb
  • button
  • calendar
  • card
  • carousel
  • checkbox
  • collapsible
  • combobox
  • command
  • context-menu
  • data-table
  • date-picker
  • dialog
  • dropdown-menu
  • form-field
  • hover-card
  • icon
  • input
  • input-otp
  • label
  • menubar
  • navigation-menu
  • pagination
  • popover
  • progress
  • radio-group
  • scroll-area
  • select
  • separator
  • sheet
  • skeleton
  • slider
  • sonner
  • spinner
  • switch
  • table
  • tabs
  • textarea
  • toggle
  • toggle-group
  • tooltip
  • typography

Others

  • trpc
  • nx
  • repo
  • cli

What is the current behavior?

The tooltip component requires users to manually provide aria-describedby attributes, often leading to invalid implementations like aria-describedby="Hello world" which don't reference actual DOM elements. This breaks accessibility as screen readers cannot properly announce tooltip content.

Closes #781

What is the new behavior?

The tooltip component automatically generates unique IDs for tooltip content and sets the aria-describedby attribute on trigger elements. Screen readers can now properly access tooltip descriptions without manual configuration. Manual aria-describedby values are still respected when provided.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This change follows Angular Material's approach and maintains backward compatibility while fixing the accessibility issue described in #781.
EOF < /dev/null

@MatanShushan MatanShushan force-pushed the fix/tooltip-aria-describedby-accessibility branch from e06560a to 79b05bb Compare August 8, 2025 21:33
The tooltip component now automatically generates and sets a unique
aria-describedby attribute that references the tooltip content's ID.
This eliminates the need for manual configuration and ensures proper
screen reader compatibility.

Previously, users had to manually provide aria-describedby values,
often incorrectly as shown in documentation examples. The component
now follows Angular Material's approach by programmatically managing
the ARIA relationship.

Closes spartan-ng#781

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@MatanShushan MatanShushan force-pushed the fix/tooltip-aria-describedby-accessibility branch from 79b05bb to b07ce7a Compare August 8, 2025 22:07
Resolve axe accessibility check timeouts by ensuring tooltip ARIA
attributes only exist when tooltip is visible.

Changes:
- Only add role="tooltip" and id when tooltip isVisible()
- Clean up aria-describedby when tooltip is detached
- Prevent invalid ARIA references to hidden elements

Fixes e2e test failures in toggle-group due to accessibility violations
caused by always-present tooltip roles and invalid aria-describedby refs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@MatanShushan MatanShushan force-pushed the fix/tooltip-aria-describedby-accessibility branch from 4f14281 to 5e9f768 Compare August 8, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltip misuses the aria-describedby attribute
1 participant