react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

PreviewTrigger: the preview dialog has no accessible name

Open clement-loridan opened this issue 4 weeks ago • 3 comments

Provide a general summary of the issue here

The popover of a PreviewTrigger renders role="dialog" with no accessible name. axe reports aria-dialog-name (serious).

🤔 Expected Behavior?

The preview dialog is named by its trigger, as a Dialog inside a DialogTrigger is: aria-labelledby points to the trigger's id when the app gives no aria-label or aria-labelledby.

😯 Current Behavior

  • Popover sets role="dialog" when trigger === 'PreviewTrigger'. It takes its name only from its own aria-label and aria-labelledby props.
  • usePreviewTrigger returns popoverProps with id, onFocusWithin and onBlurWithin: no aria-labelledby.
  • A screen reader that moves into the preview hears an unnamed dialog.

💁 Possible Solution

In usePreviewTrigger, give the trigger an id and return 'aria-labelledby': triggerId in popoverProps, overridden by an aria-label or aria-labelledby passed to the Popover. This is what useDialog does with the DialogTrigger id.

🔦 Context

We wrap PreviewTrigger as a hover card in a design system. Until then, our hover card makes aria-label required.

🖥️ Steps to Reproduce

  1. Render <PreviewTrigger><Link href="/item">Item</Link><Popover><p>Summary</p></Popover></PreviewTrigger>.
  2. Focus the link and wait for the preview.
  3. Run axe, or inspect the popover: role="dialog", no aria-label, no aria-labelledby.

Version

react-aria-components 1.22.1

What browsers are you seeing the problem on?

Chrome

What operating system are you using?

macOS

clement-loridan avatar Nov 04 '26 11:11 clement-loridan

Thanks for catching this, sounds reasonable to have it default to the trigger as its aria-labelledby. Looks like our docs for PreviewTrigger are also missing aria-labels on the examples, would lean towards adding manual aria-labels rather than linking to the triggers for clarity. If you'd like, feel free to open a PR for this otherwise the team will see about adding it to our backlog.

LFDanLu avatar Nov 04 '26 21:11 LFDanLu

Hi @LFDanLu, thanks for the pointer. I'd like to take this one, unless @clement-loridan is already working on it, in which case I'm happy to leave it.

I have a change ready and tested locally. In PreviewTrigger I give the trigger an id and pass it to the Popover as a fallback aria-labelledby, the same way DialogTrigger does, and I add aria-labels to the PreviewTrigger docs examples as you suggested. There are regression tests for the default name, a trigger with its own id, and an explicit aria-label or aria-labelledby on the Popover.

One dependency: aria-labelledby outranks aria-label, so an aria-label on the Popover would be hidden by the fallback unless the Popover drops the context label, which is what #10789 does. Would you prefer that I wait for #10789 to merge and send a PreviewTrigger-only PR, or include the small PreviewTrigger-scoped guard in mine?

I used an AI assistant (Claude Code) for the investigation and drafting, and I will say so in the PR.

therealemmanueloppong avatar Nov 05 '26 21:11 therealemmanueloppong

@therealemmanueloppong go for it! Thanks for the reminder for https://github.com/adobe/react-spectrum/pull/10789, I've just approved and hit the merge button for that one so you can send a preview trigger only PR after that goes in

LFDanLu avatar Nov 05 '26 23:11 LFDanLu