-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(dialog): add aria-describedby support for alertdialog role #9924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
costajohnt
wants to merge
11
commits into
adobe:main
Choose a base branch
from
costajohnt:fix/alert-dialog-aria-describedby
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6556634
fix(dialog): add aria-describedby support for alertdialog role
costajohnt afbfd15
fix: wire contentProps via TextContext for RAC alertdialog aria-descr…
costajohnt eec13ab
test: add RAC integration test for alertdialog aria-describedby via T…
costajohnt 368799e
fix: sort TextContext import alphabetically in RAC Dialog
costajohnt cf8cdb0
update tests, add warning to RAC
yihuiliao 4408961
add describedby to s2 alert dialog
yihuiliao 2708926
fix test
yihuiliao 4348b5b
Merge branch 'main' into fix/alert-dialog-aria-describedby
yihuiliao a3b9ee8
refactor, add tests, fix image labels in examples
snowystinger 91fae1d
fix lint
snowystinger 47b03f1
fix: allow aria-describedby override in v3 AlertDialog
costajohnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright 2025 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import {act, pointerMap, render} from '@react-spectrum/test-utils-internal'; | ||
| import {ActionButton} from '../src/ActionButton'; | ||
| import {AlertDialog} from '../src/AlertDialog'; | ||
| import {Content} from '../src/Content'; | ||
| import {DialogTrigger} from '../src/DialogTrigger'; | ||
| import React from 'react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| describe('AlertDialog', () => { | ||
| let user; | ||
| beforeAll(() => { | ||
| jest.useFakeTimers(); | ||
| user = userEvent.setup({delay: null, pointerMap}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| act(() => jest.runAllTimers()); | ||
| }); | ||
|
|
||
| afterAll(function () { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('automatically links to the content with aria-describedby', async () => { | ||
| let {getByRole} = render( | ||
| <DialogTrigger> | ||
| <ActionButton>Open dialog</ActionButton> | ||
| <AlertDialog title="Test" primaryActionLabel="Test"> | ||
| Test content | ||
| </AlertDialog> | ||
| </DialogTrigger> | ||
| ); | ||
|
|
||
| let trigger = getByRole('button'); | ||
| await user.click(trigger); | ||
| act(() => {jest.runAllTimers();}); | ||
| let dialog = getByRole('alertdialog'); | ||
| expect(dialog).toBeVisible(); | ||
| let description = dialog.getAttribute('aria-describedby'); | ||
| expect(description).toBeDefined(); | ||
| let content = document.getElementById(description!); | ||
| expect(content).toHaveTextContent('Test content'); | ||
| }); | ||
|
|
||
| it('accepts custom aria-describedby', async () => { | ||
| let {getByRole} = render( | ||
| <DialogTrigger> | ||
| <ActionButton>Open dialog</ActionButton> | ||
| <AlertDialog aria-describedby="content-id" title="Test" primaryActionLabel="Test"> | ||
| <Content><p id="content-id">Test content</p><p>Extra content</p></Content> | ||
| </AlertDialog> | ||
| </DialogTrigger> | ||
| ); | ||
|
|
||
| let trigger = getByRole('button'); | ||
| await user.click(trigger); | ||
| act(() => {jest.runAllTimers();}); | ||
| let dialog = getByRole('alertdialog'); | ||
| expect(dialog).toBeVisible(); | ||
| let description = dialog.getAttribute('aria-describedby'); | ||
| expect(description).toBeDefined(); | ||
| let content = document.getElementById(description!); | ||
| expect(content).toHaveTextContent('Test content'); | ||
| }); | ||
| }); |
106 changes: 106 additions & 0 deletions
106
packages/@react-spectrum/s2/test/StandardDialog.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Copyright 2025 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import {act, pointerMap, render} from '@react-spectrum/test-utils-internal'; | ||
| import {ActionButton} from '../src/ActionButton'; | ||
| import {Button} from '../src/Button'; | ||
| import {ButtonGroup} from '../src/ButtonGroup'; | ||
| import {Checkbox} from '../src/Checkbox'; | ||
| import {Content, Footer, Header, Heading} from '../src/Content'; | ||
| import {Dialog} from '../src/Dialog'; | ||
| import {DialogTrigger} from '../src/DialogTrigger'; | ||
| import React from 'react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| describe('StandardDialog', () => { | ||
| let user; | ||
| beforeAll(() => { | ||
| jest.useFakeTimers(); | ||
| user = userEvent.setup({delay: null, pointerMap}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| act(() => jest.runAllTimers()); | ||
| }); | ||
|
|
||
| afterAll(function () { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('does not automatically add aria-describedby', async () => { | ||
| let {getByRole} = render( | ||
| <DialogTrigger> | ||
| <ActionButton>Open dialog</ActionButton> | ||
| <Dialog> | ||
| {({close}) => ( | ||
| <> | ||
| <Heading slot="title">Dialog title</Heading> | ||
| <Header>Header</Header> | ||
| <Content> | ||
| This is the content of the dialog. | ||
| </Content> | ||
| <Footer><Checkbox>Don't show this again</Checkbox></Footer> | ||
| <ButtonGroup> | ||
| <Button onPress={close} variant="secondary">Cancel</Button> | ||
| <Button onPress={close} variant="accent">Save</Button> | ||
| </ButtonGroup> | ||
| </> | ||
| )} | ||
| </Dialog> | ||
| </DialogTrigger> | ||
| ); | ||
|
|
||
| let trigger = getByRole('button'); | ||
| await user.click(trigger); | ||
| act(() => {jest.runAllTimers();}); | ||
| let dialog = getByRole('dialog'); | ||
| expect(dialog).toBeVisible(); | ||
| let description = dialog.getAttribute('aria-describedby'); | ||
| expect(description).toBeNull(); | ||
| }); | ||
|
|
||
| it('accepts custom aria-describedby', async () => { | ||
| let {getByRole} = render( | ||
| <DialogTrigger> | ||
| <ActionButton>Open dialog</ActionButton> | ||
| <Dialog aria-describedby="content-id"> | ||
| {({close}) => ( | ||
| <> | ||
| <Heading slot="title">Dialog title</Heading> | ||
| <Header>Header</Header> | ||
| <Content> | ||
| <p id="content-id">This is the content of the dialog.</p> | ||
| <p>Extra content</p> | ||
| </Content> | ||
| <Footer><Checkbox>Don't show this again</Checkbox></Footer> | ||
| <ButtonGroup> | ||
| <Button onPress={close} variant="secondary">Cancel</Button> | ||
| <Button onPress={close} variant="accent">Save</Button> | ||
| </ButtonGroup> | ||
| </> | ||
| )} | ||
| </Dialog> | ||
| </DialogTrigger> | ||
| ); | ||
|
|
||
| let trigger = getByRole('button'); | ||
| await user.click(trigger); | ||
| act(() => {jest.runAllTimers();}); | ||
| let dialog = getByRole('dialog'); | ||
| expect(dialog).toBeVisible(); | ||
| let description = dialog.getAttribute('aria-describedby'); | ||
| expect(description).toBeDefined(); | ||
| let content = document.getElementById(description!); | ||
| expect(content).toHaveTextContent('This is the content of the dialog.'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ function Example(props) { | |
| <Dialog {...props}/* PROPS */> | ||
| {({close}) => ( | ||
| <> | ||
| <Image slot="hero" src={heroImage} /> | ||
| <Image slot="hero" src={heroImage} alt="" /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| <Heading slot="title">Subscribe to our newsletter</Heading> | ||
| <Content> | ||
| <p>Enter your information to subscribe to our newsletter and receive updates about new features and announcements.</p> | ||
|
|
@@ -76,7 +76,7 @@ function Example(props) { | |
| <Dialog {...props}/* PROPS */> | ||
| {({close}) => ( | ||
| <> | ||
| <Image slot="hero" src={heroImage} /> | ||
| <Image slot="hero" src={heroImage} alt="" /> | ||
| <Heading slot="title">Dialog Title</Heading> | ||
| <Header>Header</Header> | ||
| <Content> | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.Consumerand pass the props on that context directly to theContentContextbelow.Preferences?