react-spectrum
ba923ddf - fix(dialog): add aria-describedby support for alertdialog role (#9924)

Commit
8 days ago
fix(dialog): add aria-describedby support for alertdialog role (#9924) * fix(dialog): add aria-describedby support for alertdialog role AlertDialog was rendering with role="alertdialog" but without aria-describedby, which the WAI-ARIA spec recommends for alertdialogs to reference the alert message content. Changes: - useDialog hook: generate a content ID via useSlotId when role is "alertdialog", return contentProps with the ID, and set aria-describedby on the dialog element - V3 Dialog: spread contentProps onto the content slot so the Content element receives the generated ID - RAC Dialog: destructure contentProps (available for user composition) The aria-describedby is only auto-wired for alertdialog role. Regular dialogs are unaffected. Users can override via the aria-describedby prop. Fixes #9916 * fix: wire contentProps via TextContext for RAC alertdialog aria-describedby * test: add RAC integration test for alertdialog aria-describedby via Text slot * fix: sort TextContext import alphabetically in RAC Dialog * update tests, add warning to RAC * add describedby to s2 alert dialog * fix test * refactor, add tests, fix image labels in examples * fix lint * fix: allow aria-describedby override in v3 AlertDialog Extends SpectrumAlertDialogProps with AriaLabelingProps and passes {labelable: true} to filterDOMProps so user-supplied aria-describedby flows through to the inner Dialog instead of being stripped. Mirrors the S2 AlertDialog treatment already merged by snowystinger, and aligns v3 AlertDialog with regular v3 Dialog, which has these props transitively via AriaDialogProps. Adds a test verifying the override reaches the rendered alertdialog element. * fix(useDialog): drop contentId when aria-describedby is user-provided If the consumer supplies their own aria-describedby on an alertdialog, useDialog no longer generates a slot id for contentProps. This mirrors the existing handling of titleId vs aria-label and prevents downstream wrappers (e.g. RAC Dialog's TextContext for the description slot) from receiving an id no one references. Adds a test covering the override path. * fix(s2): wire aria-describedby on S2 AlertDialog via explicit contentId Generates a contentId in S2 AlertDialog and passes it to both the underlying Dialog (as aria-describedby) and to <Content /> (as id). This puts the aria-describedby target directly on the Content element rather than on the Text slot wrapper, and keeps the wiring contained within AlertDialog instead of relying on the RAC TextContext path. A consumer-supplied aria-describedby continues to take precedence; in that case we omit the generated id from <Content /> so we don't add an unused id. * fix(s2): import useId from react-aria/useId, not 'react' React.useId is React 18+ only, breaking test-16 and test-17 in CI. Every other S2 file uses the polyfilled useId from react-aria/useId. * fix some merge changes * move warning down to hook and remove extra code from s2 * test: use renamed DialogTester.getDialog() API after merge main renamed the DialogTester getters to methods (get dialog() -> getDialog()). The alertdialog aria-describedby test still used the old .dialog getter, which now returns undefined and fails the assertions. Match the getDialog() API already used elsewhere in this file. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * make more forgiving since spec says "should" --------- Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com> Co-authored-by: Rob Snow <rsnow@adobe.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Author
Parents
Loading