PreviewTrigger: the preview dialog has no accessible name
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
Popoversetsrole="dialog"whentrigger === 'PreviewTrigger'. It takes its name only from its ownaria-labelandaria-labelledbyprops.usePreviewTriggerreturnspopoverPropswithid,onFocusWithinandonBlurWithin: noaria-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
- Render
<PreviewTrigger><Link href="/item">Item</Link><Popover><p>Summary</p></Popover></PreviewTrigger>. - Focus the link and wait for the preview.
- Run axe, or inspect the popover:
role="dialog", noaria-label, noaria-labelledby.
Version
react-aria-components 1.22.1
What browsers are you seeing the problem on?
Chrome
What operating system are you using?
macOS
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.
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 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