Skip to content

fix(core): add role="tooltip" to the Tooltip layer - #3243

Merged
cixzhang merged 2 commits into
meta:mainfrom
durvesh1992:fix/tooltip-role-a11y
Jun 29, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
durvesh1992:fix/tooltip-role-a11y

Conversation

@durvesh1992

Copy link
Copy Markdown
Contributor

Summary

Addresses #3240 (option 1, the priority ask). The Tooltip floating layer rendered with no role, so:

  • it didn't complete the ARIA tooltip pattern (the trigger already sets aria-describedby → layer id), and
  • test tooling had no stable, non-hashed selector for the layer.

Added an optional role to the layer render props (useLayer ContextRenderProps → popover element) and pass role="tooltip" from useTooltip. This is both an a11y correctness improvement and the testability hook the issue asks for.

Testing

  • New test: the layer is reachable via getByRole('tooltip'), contains the content, and the trigger's aria-describedby matches the layer id.
  • Tooltip 7/7, HoverCard 22/22, Popover 14/14 pass — the useLayer change is additive (role is optional, omitted when unset, so other layer consumers are unaffected).

Scope / follow-ups

Kept this to the Tooltip role (issue's #1). The issue's other asks are deferred as separate concerns:

  • HoverCard role — there's no unambiguous ARIA role for a hover-triggered rich card (dialog implies modal), so that's a design call.
  • data-state="open|closed" — needs wiring the layer's open state into the render (reactive), a bigger change to the shared hook.
  • data-testid forwarding — straightforward follow-up once the above direction is settled.

Happy to do any of those if you'd like.

Changeset

Included (@astryxdesign/core patch).

Addresses meta#3240. The Tooltip floating layer had no role, so it didn't
complete the ARIA tooltip pattern (trigger already sets aria-describedby
to the layer id) and test tooling had no stable selector for it. Add an
optional role on the layer render props and pass role='tooltip' from
useTooltip. +test asserting role + the aria-describedby link.

Scoped to the Tooltip role (issue's meta#1 priority). HoverCard role,
data-state, and data-testid forwarding are noted as follow-ups.
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 29, 2026
Comment thread .changeset/tooltip-role-a11y.md Outdated
'@astryxdesign/core': patch
---

[fix] Tooltip: add `role="tooltip"` to the floating layer, completing the ARIA tooltip pattern (the trigger already links to it via `aria-describedby`). Also gives test tooling a stable, non-hashed selector for the layer (#3240). Plumbed via a new optional `role` on the layer render props.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this part is needed, since it can be assumed that the role is stable:

Also gives test tooling a stable, non-hashed selector for the layer (#3240)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — trimmed that clause from the changeset.

@Daniel15 Daniel15 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me. It would be good to also update hovercards and popovers to have role="dialog".

I double-checked the layers for typeahead and tokenizer and verified that they already have role="listbox".

Addresses review feedback on meta#3243 (@Daniel15):
- Add role='dialog' to the HoverCard floating layer (Popover already
  exposes role='dialog' via usePopover).
- Trim the changeset's 'stable selector' clause (role stability can be
  assumed).
+test asserting HoverCard layer role='dialog'.
@durvesh1992

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed both:

  • HoverCard now gets role="dialog" (via the same layer role prop), with a test.
  • Popover already exposes role="dialog" — it's on the dialog content element in usePopover (with aria-modal + aria-label, and the trigger has aria-haspopup="dialog"/aria-expanded/aria-controls), so I left it as-is. Happy to also mirror it onto the outer layer element if you'd prefer it there.
  • Trimmed the changeset's "stable selector" line.
  • 👍 confirmed Typeahead/Tokenizer already carry role="listbox".

Tooltip/HoverCard/Popover tests all green (44).

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I can't believe we missed this.

@cixzhang
cixzhang merged commit e839b09 into meta:main Jun 29, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants