-
Notifications
You must be signed in to change notification settings - Fork 894
[a11y] EuiScreenReaderLive component
#5567
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4e383e6
euiscreenreaderlive
thompsongl 7bf6aac
CL
thompsongl 3d9d074
more tests
thompsongl 5323354
use default value
thompsongl 9d27ef5
fix circular dep
thompsongl bdfb588
docs
thompsongl dba06dd
types
thompsongl af47fcb
mdn link
thompsongl 3e8b607
Merge branch 'main' into 3733-screenreaderstatus
thompsongl 69b4c80
Merge branch 'main' into 3733-screenreaderstatus
thompsongl 45a4e83
docs
thompsongl 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { | ||
| EuiCode, | ||
| EuiFieldNumber, | ||
| EuiFormRow, | ||
| EuiScreenReaderLive, | ||
| EuiSpacer, | ||
| EuiText, | ||
| } from '../../../../src/components'; | ||
|
|
||
| export default () => { | ||
| const [value, setValue] = useState(1); | ||
| return ( | ||
| <> | ||
| <EuiFormRow label="Current value"> | ||
| <EuiFieldNumber | ||
| placeholder="Current value" | ||
| value={value} | ||
| onChange={(e) => setValue(Number(e.target.value))} | ||
| min={0} | ||
| /> | ||
| </EuiFormRow> | ||
| <EuiSpacer /> | ||
| <EuiText> | ||
| <p> | ||
| <em>Content announced by screen reader: </em> | ||
| <EuiCode>Current value: {value}</EuiCode> | ||
| </p> | ||
| <EuiScreenReaderLive> | ||
| <p>Current value: {value}</p> | ||
| </EuiScreenReaderLive> | ||
| </EuiText> | ||
| </> | ||
| ); | ||
| }; |
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
153 changes: 153 additions & 0 deletions
153
...omponents/accessibility/screen_reader_live/__snapshots__/screen_reader_live.test.tsx.snap
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,153 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`EuiScreenReaderLive with a static configuration accepts \`aria-live\` 1`] = ` | ||
| <div | ||
| class="euiScreenReaderOnly" | ||
| > | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="assertive" | ||
| role="status" | ||
| /> | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="assertive" | ||
| role="status" | ||
| > | ||
| <p> | ||
| This paragraph is not visible to sighted users but will be read by screenreaders. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`EuiScreenReaderLive with a static configuration accepts \`role\` 1`] = ` | ||
| <div | ||
| class="euiScreenReaderOnly" | ||
| > | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="log" | ||
| /> | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="log" | ||
| > | ||
| <p> | ||
| This paragraph is not visible to sighted users but will be read by screenreaders. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`EuiScreenReaderLive with a static configuration does not render screen reader content when inactive 1`] = ` | ||
| <div | ||
| class="euiScreenReaderOnly" | ||
| > | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| /> | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| /> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`EuiScreenReaderLive with a static configuration renders screen reader content when active 1`] = ` | ||
| <div | ||
| class="euiScreenReaderOnly" | ||
| > | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| /> | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| > | ||
| <p> | ||
| This paragraph is not visible to sighted users but will be read by screenreaders. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`EuiScreenReaderLive with dynamic properties alternates rendering screen reader content into the second live region when changed/toggled 1`] = ` | ||
| <Component> | ||
| <div> | ||
| <button | ||
| data-test-subj="increment" | ||
| onClick={[Function]} | ||
| > | ||
| Increment | ||
| </button> | ||
| <EuiScreenReaderLive> | ||
| <EuiScreenReaderOnly> | ||
| <div | ||
| className="euiScreenReaderOnly" | ||
| > | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| /> | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| > | ||
| <p> | ||
| Number of active options: | ||
| 1 | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </EuiScreenReaderOnly> | ||
| </EuiScreenReaderLive> | ||
| </div> | ||
| </Component> | ||
| `; | ||
|
|
||
| exports[`EuiScreenReaderLive with dynamic properties initially renders screen reader content in the first live region 1`] = ` | ||
| <Component> | ||
| <div> | ||
| <button | ||
| data-test-subj="increment" | ||
| onClick={[Function]} | ||
| > | ||
| Increment | ||
| </button> | ||
| <EuiScreenReaderLive> | ||
| <EuiScreenReaderOnly> | ||
| <div | ||
| className="euiScreenReaderOnly" | ||
| > | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| > | ||
| <p> | ||
| Number of active options: | ||
| 0 | ||
| </p> | ||
| </div> | ||
| <div | ||
| aria-atomic="true" | ||
| aria-live="polite" | ||
| role="status" | ||
| /> | ||
| </div> | ||
| </EuiScreenReaderOnly> | ||
| </EuiScreenReaderLive> | ||
| </div> | ||
| </Component> | ||
| `; |
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,12 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| export { | ||
| EuiScreenReaderLive, | ||
| EuiScreenReaderLiveProps, | ||
| } from './screen_reader_live'; |
93 changes: 93 additions & 0 deletions
93
src/components/accessibility/screen_reader_live/screen_reader_live.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,93 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React, { useState } from 'react'; | ||
| import { mount, render } from 'enzyme'; | ||
|
|
||
| import { findTestSubject } from '../../../test'; | ||
|
|
||
| import { EuiScreenReaderLive } from './screen_reader_live'; | ||
|
|
||
| describe('EuiScreenReaderLive', () => { | ||
| describe('with a static configuration', () => { | ||
| const content = ( | ||
| <p> | ||
| This paragraph is not visible to sighted users but will be read by | ||
| screenreaders. | ||
| </p> | ||
| ); | ||
|
|
||
| it('renders screen reader content when active', () => { | ||
| const component = render( | ||
| <EuiScreenReaderLive isActive={true}>{content}</EuiScreenReaderLive> | ||
| ); | ||
|
|
||
| expect(component).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('does not render screen reader content when inactive', () => { | ||
| const component = render( | ||
| <EuiScreenReaderLive isActive={false}>{content}</EuiScreenReaderLive> | ||
| ); | ||
|
|
||
| expect(component).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('accepts `role`', () => { | ||
| const component = render( | ||
| <EuiScreenReaderLive role="log">{content}</EuiScreenReaderLive> | ||
| ); | ||
|
|
||
| expect(component).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('accepts `aria-live`', () => { | ||
| const component = render( | ||
| <EuiScreenReaderLive aria-live="assertive"> | ||
| {content} | ||
| </EuiScreenReaderLive> | ||
| ); | ||
|
|
||
| expect(component).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with dynamic properties', () => { | ||
| const Component = () => { | ||
| const [activeOptions, setActiveOptions] = useState(0); | ||
|
|
||
| return ( | ||
| <div> | ||
| <button | ||
| data-test-subj="increment" | ||
| onClick={() => setActiveOptions(1)} | ||
| > | ||
| Increment | ||
| </button> | ||
| <EuiScreenReaderLive> | ||
| <p>Number of active options: {activeOptions}</p> | ||
| </EuiScreenReaderLive> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| it('initially renders screen reader content in the first live region', () => { | ||
| const component = mount(<Component />); | ||
|
|
||
| expect(component).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('alternates rendering screen reader content into the second live region when changed/toggled', () => { | ||
| const component = mount(<Component />); | ||
|
|
||
| findTestSubject(component, 'increment').simulate('click'); | ||
|
|
||
| expect(component).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.