Skip to content

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

Merged
snowystinger merged 21 commits into
adobe:mainfrom
costajohnt:fix/alert-dialog-aria-describedby
Jun 25, 2026
Merged

snowystinger merged 21 commits into
adobe:mainfrom
costajohnt:fix/alert-dialog-aria-describedby

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Summary

Fixes #9916

AlertDialog was rendering with role="alertdialog" but without aria-describedby. Per WAI-ARIA 1.2, alertdialogs should reference their alert message content via aria-describedby.

Changes:

  • useDialog hook: generates a content ID via useSlotId when role is alertdialog, returns contentProps with the ID, sets aria-describedby on the dialog element
  • V3 Dialog: spreads contentProps onto the content slot
  • RAC Dialog: destructures contentProps (available for user composition)

Only auto-wired for alertdialog role. Regular dialogs are unaffected. Users can override via the aria-describedby prop.

Note: VoiceOver on macOS currently does not announce aria-describedby on alertdialogs (WebKit bug 282773), but this is still the correct spec behavior.

Test plan

  • Added 3 tests in useDialog.test.js (aria-describedby set for alertdialog, not set for dialog, override works)
  • Added 1 test in AlertDialog.test.js (content element linked via aria-describedby)
  • All 42 dialog tests pass across all 4 test suites
  • No regressions in RAC Dialog tests

@github-actions github-actions Bot added the RAC label Apr 14, 2026
@costajohnt
costajohnt force-pushed the fix/alert-dialog-aria-describedby branch from 2f3f421 to 3798d48 Compare April 14, 2026 20:46

@yihuiliao yihuiliao 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.

we also still need to update the S2 Alert Dialog so that it hooks up the aria-describedby. i think the easiest way to do that is just to create an contentId in the S2 AlertDialog file and pass it to <Content />

i was hoping we could utilize the RAC Dialog to handle it but i don't think it would be that simple

title: {...titleProps, level: 2}
}
}],
[TextContext, {

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'm okay with adding this but wondering how other folks on the team feel. like @snowystinger said, we should probably also add a dev warning in production if the role=alert-dialog if aria-describedby is missing

if we stick with this, we need to remember to add this the docs, probably just to the API section where we document the other slots

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 think a warning is fine, and we should definitely update the docs as well since right now the dialog body content in the examples are just <p>. We'll probably have to add a specific section for "alert dialog" setup to disambiguate this case from a standard dialog case.

I'd also be curious how well alert dialogs already announce without the additional aria-describedby since as the 1.2 ARIA does mention that AT may have a backup way of announcing the dialog's content. VO on Chrome/Safari doesn't seem to but we'll have to do a sweep

@snowystinger snowystinger Apr 15, 2026 •

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'm a little worried about how long the announcements will be if we default to the content as well, i guess less common in Alert dialogs in particular

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
@costajohnt
costajohnt force-pushed the fix/alert-dialog-aria-describedby branch from 3798d48 to 368799e Compare April 16, 2026 01:59
@github-actions github-actions Bot added the S2 label Apr 22, 2026
role="alertdialog"
ref={ref}
size={props.size}
aria-describedby={contentId}

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.

We should also allow users to override it in S2 and v3

]}>
{children}
</Provider>
<Text slot="description" style={{display: 'contents'}}>

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.

Because we added a new TextContext into Dialog in RAC, this is how we should probably pick up the context in S2. Note, because of display 'contents', this should result in no layout changes visually. It does add an extra dom node though, that no one should really be trying to access.

Another option is to make use of the TextContext.Consumer and pass the props on that context directly to the ContentContext below.

Preferences?

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.

hm i kinda like the idea of using TextContext.Consumer

{({close}) => (
<>
<Image slot="hero" src={heroImage} />
<Image slot="hero" src={heroImage} alt="" />

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.

Noticed the announcement for these dialogs was bad. The images don't do anything here and are boring gradients, so I made them presentational

}],
[TextContext, {
slots: {
[DEFAULT_SLOT]: {},

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.

to team, would we prefer this on the default context?

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 think i prefer to keep it so that the user has to add slot="description"

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.
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.
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.
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.
@github-actions github-actions Bot added the Dialog label May 9, 2026
@costajohnt

Copy link
Copy Markdown
Contributor Author

Just pushed c52579c to fix the CI failure on test-16 and test-17. The S2 AlertDialog was importing useId from 'react', which is React 18+ only. Every other S2 file uses react-aria/useId, so I matched that pattern.

On the TextContext.Consumer thread on Dialog.tsx:196: I want to make sure I'm reading the conversation right before I touch it. @snowystinger suggested the Consumer approach as an alternative to the current <Text slot="description"> wrapper, and @yihuiliao said "i kinda like the idea of using TextContext.Consumer". Should I take that as a go-ahead to refactor in this PR, or is it still an open design choice you'd like to discuss further? Happy to do the swap if you want it, just don't want to land it without a clear thumbs-up.

# Conflicts:
#	packages/@adobe/react-spectrum/src/dialog/Dialog.tsx
#	packages/react-aria-components/src/Dialog.tsx
#	packages/react-aria-components/test/RadioGroup.test.js
#	packages/react-aria/src/dialog/useDialog.ts
snowystinger
snowystinger previously approved these changes May 11, 2026
…ia-describedby

# Conflicts:
#	packages/@adobe/react-spectrum/src/dialog/AlertDialog.tsx
#	packages/@adobe/react-spectrum/src/dialog/Dialog.tsx
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 <[email protected]>
snowystinger
snowystinger previously approved these changes Jun 9, 2026

@snowystinger snowystinger 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.

re-approving

@snowystinger
snowystinger added this pull request to the merge queue Jun 25, 2026
Merged via the queue into adobe:main with commit ba923dd Jun 25, 2026
4 checks passed
jsmitrah added a commit to jsmitrah/react-spectrum that referenced this pull request Jun 29, 2026
fix: resolve lint and CI test compilation errors

fix(table): floor fractional table width so columns don't overflow (adobe#10238)

* fix(table): floor fractional table width so columns don't overflow

calculateColumnSizes relies on cascadeRounding, which assumes the target column
sizes sum to an integer. With a fractional table width (e.g. a percentage-based
size) that invariant breaks and the rounded widths can exceed the available
width by 1px, producing an unexpected horizontal scrollbar. Flooring the
available width keeps the sum integral; integer widths are unchanged.

Adds a regression test to TableUtils. Fixes adobe#9448.

* Keep columns flush with a fractional table width

Address review: instead of flooring the available width (which left a
sub-pixel gap between the last column and the table edge), assign the
leftover fraction to the last column inside cascadeRounding so the column
widths sum exactly to the available width. Integer widths are unchanged.

* Fix failing resize tests; keep integer widths whole

The previous revision added the fractional remainder inside cascadeRounding
using `fpTotal - intTotal`, but floating-point accumulation could leave a
tiny residue on the last column even for integer table widths, breaking
tests that assume whole-number widths (e.g. tableResizingTests).

Revert cascadeRounding to its integer-only form and instead split the
available width in calculateColumnSizes: distribute the floored (whole-pixel)
width across the columns, then add the leftover fraction to the last column.
Integer widths are now exactly whole numbers again, and a fractional width
(e.g. 1000.5 -> [500, 500.5]) keeps the columns flush with the table edge.

* Add test for fractional table widths with fp rounding error

Covers a table width like 1000.7 where the leftover fraction lands on the
last column. The columns still sum exactly to the available width and all
but the last column are whole numbers; the last column is within one ULP
of the expected fractional value.

* use number string manipulation to make exact math

---------

Co-authored-by: Rob Snow <[email protected]>

fix: shadcn registry build (adobe#10263)

fix: make sure trackpad taps properly fire press events consistently (adobe#10225)

* fix: make sure trackpad taps are not considered as virtual clicks

* didnt save?

fix(dialog): add aria-describedby support for alertdialog role (adobe#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 adobe#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 <[email protected]>

* make more forgiving since spec says "should"

---------

Co-authored-by: Yihui Liao <[email protected]>
Co-authored-by: Rob Snow <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>

fix: re-export RenderProps-related types from react-aria-components to (adobe#9955)

fix downstream TS2742

The v1.17.0 types refactor split the bundled types.d.ts into per-source
files. RenderProps extends StyleRenderProps extends DOMRenderProps, and
StyleRenderProps['style'] uses StyleOrFunction — neither was publicly
nameable. Downstream packages built with composite/declaration emit then
fail with TS2742 on any inferred type whose expansion crosses these
names.

Adds `export` to StyleOrFunction and re-exports DOMRenderProps,
PossibleLinkDOMRenderProps, DOMRenderFunction, ClassNameOrFunction,
StyleOrFunction, and ChildrenOrFunction from the package entry.
Type-only,
additive — no runtime impact.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Robert Snow <[email protected]>

fix(useId): prevent FinalizationRegistry entry leak in useId (adobe#9853)

* fix(useId): avoid FinalizationRegistry entry leak in useId

* fix test in React 16/17

* add comments to test

* additional test: changing the id should unregister the old token and register the new one

---------

Co-authored-by: Robert Snow <[email protected]>

fix: prefer ancestor drop target over nearest-by-distance in DragManager (adobe#10170)

Co-authored-by: Matt Van Horn <[email protected]>
Co-authored-by: Robert Snow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AlertDialog renders without aria-describedby

6 participants