-
Notifications
You must be signed in to change notification settings - Fork 671
Replace aria-live and LiveRegion usage
#7230
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
Changes from 3 commits
a88f02b
cf30b4d
e774fa5
1e5cb99
87be474
7566471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
|
|
||
| Replaces 'aria-live' usage and removes internal LiveRegion component |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import React from 'react' | |
| import type {SubTreeState} from './TreeView' | ||
| import {TreeView} from './TreeView' | ||
| import {GearIcon} from '@primer/octicons-react' | ||
| import {getLiveRegion} from '../live-region/__tests__/test-helpers' | ||
|
|
||
| // TODO: Move this function into a shared location | ||
| function renderWithTheme( | ||
|
|
@@ -1392,6 +1393,10 @@ describe('State', () => { | |
|
|
||
| describe('Asynchronous loading', () => { | ||
| it('updates aria live region when loading is done', () => { | ||
| // Set up live region for this test | ||
| const liveRegionEl = document.createElement('live-region') | ||
| document.body.appendChild(liveRegionEl) | ||
|
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. The live region utilities should be doing this automatically, let me know if not 👀 I think test-wise we just have to have a clean up for them, e.g. afterEach(() => {
const liveRegion = document.querySelector('live-region');
document.body.removeChild(liveRegion);
});
Contributor
Author
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. That's what I thought too, but they weren't.
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. @mperrotti if I remove these lines from the test it still seems to pass, are you seeing that too or no?
Contributor
Author
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. Huh, that's odd. The failures may have been caused by something else I changed. Will remove. |
||
|
|
||
| function TestTree() { | ||
| const [state, setState] = React.useState<SubTreeState>('initial') | ||
|
|
||
|
|
@@ -1426,15 +1431,15 @@ describe('Asynchronous loading', () => { | |
| const {getByRole} = renderWithTheme(<TestTree />) | ||
|
|
||
| const doneButton = getByRole('button', {name: 'Load'}) | ||
| const liveRegion = getByRole('status') | ||
| const liveRegion = getLiveRegion() | ||
|
|
||
| // Live region should be empty | ||
| expect(liveRegion).toHaveTextContent('') | ||
| expect(liveRegion.getMessage('polite')).toBe('') | ||
|
|
||
| // Click load button to mimic async loading | ||
| fireEvent.click(doneButton) | ||
|
|
||
| expect(liveRegion).toHaveTextContent('Parent content loading') | ||
| expect(liveRegion.getMessage('polite')).toBe('Parent content loading') | ||
|
|
||
| // Click done button to mimic the completion of async loading | ||
| fireEvent.click(doneButton) | ||
|
|
@@ -1444,8 +1449,10 @@ describe('Asynchronous loading', () => { | |
| }) | ||
|
|
||
| // Live region should be updated | ||
| expect(liveRegion).not.toHaveTextContent('Child 2 is empty') | ||
| expect(liveRegion).toHaveTextContent('Parent content loaded') | ||
| expect(liveRegion.getMessage('polite')).toBe('Parent content loaded') | ||
|
|
||
| // Clean up live region | ||
| document.body.removeChild(liveRegionEl) | ||
| }) | ||
|
|
||
| it('moves focus from loading item to first child', async () => { | ||
|
|
@@ -1810,7 +1817,8 @@ describe('CSS Module Migration', () => { | |
| </TreeView> | ||
| ) | ||
|
|
||
| // Testing on the second child element because the first child element is visually hidden | ||
| expect(render(<TreeViewTestComponent />).container.children[1]).toHaveClass('test-class-name') | ||
| // Find the TreeView ul element (which should have the className) | ||
| const treeElement = render(<TreeViewTestComponent />).getByRole('tree') | ||
| expect(treeElement).toHaveClass('test-class-name') | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,7 @@ import {useIsMacOS} from '../hooks' | |||||
| import {Tooltip} from '../TooltipV2' | ||||||
| import {isSlot} from '../utils/is-slot' | ||||||
| import type {FCWithSlotMarker} from '../utils/types' | ||||||
| import {AriaStatus} from '../live-region' | ||||||
|
|
||||||
| // ---------------------------------------------------------------------------- | ||||||
| // Context | ||||||
|
|
@@ -144,8 +145,11 @@ const Root: React.FC<TreeViewProps> = ({ | |||||
| }} | ||||||
| > | ||||||
| <> | ||||||
| <VisuallyHidden role="status" aria-live="polite" aria-atomic="true"> | ||||||
| {ariaLiveMessage} | ||||||
| <VisuallyHidden> | ||||||
| {/* Message fail without passing a `key` */} | ||||||
|
||||||
| {/* Message fail without passing a `key` */} | |
| {/* Message fails without passing a `key` */} |
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.
Nope, we're getting rid of the key. Thanks though.
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.
Ooo what issue were you running into without key? 👀
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.
It just wasn't picking up the content. Here's the test failure when I don't pass a key:
FAIL @primer/react (chromium) src/TreeView/TreeView.test.tsx > Asynchronous loading > updates aria live region when loading is done
AssertionError: expected '' to be 'Parent content loading' // Object.is equality
- Expected
+ Received
- Parent content loading
❯ toBe src/TreeView/TreeView.test.tsx:1442:44
1440| fireEvent.click(doneButton)
1441|
1442| expect(liveRegion.getMessage('polite')).toBe('Parent content loading')
| ^
1443|
1444| // Click done button to mimic the completion of async loading
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.
@mperrotti it seems like the test is complaining about updates not being wrapped in act() when debugging locally, are you seeing that as well? When updating to the following it seemed to work without key:
// Click load button to mimic async loading
await act(async () => {
await user.click(doneButton)
})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.
Ahh ok I see! Will update. Thank you!
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.