-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Framework/Accessibility] Add kuiScreenReaderOnly class (#13133)
* [Framework/Accessibility] Add kuiScreenReaderOnly class * fix typo * use GuideLink * add screen_reader react component and tests * export KuiScreenReaderOnly * --wip-- [skip ci] * fix lint rule * remove obsolete snapshots
- Loading branch information
Showing
11 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
ui_framework/components/accessibility/__snapshots__/screen_reader.test.js.snap
This file contains 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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`KuiScreenReaderOnly adds an accessibility class to a child element and combines other classNames (foo, bar) given as props on the child 1`] = ` | ||
<p | ||
class="kuiScreenReaderOnly foo bar" | ||
> | ||
This paragraph is not visibile to sighted users but will be read by screenreaders. | ||
</p> | ||
`; | ||
|
||
exports[`KuiScreenReaderOnly adds an accessibility class to a child element when used with no props 1`] = ` | ||
<p | ||
class="kuiScreenReaderOnly" | ||
> | ||
This paragraph is not visibile to sighted users but will be read by screenreaders. | ||
</p> | ||
`; |
This file contains 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 @@ | ||
@import "./_screen_reader"; |
This file contains 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,8 @@ | ||
.kuiScreenReaderOnly { | ||
position: absolute; | ||
left: -10000px; | ||
top: auto; | ||
width: 1px; | ||
height: 1px; | ||
overflow: hidden; | ||
} |
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { KuiKeyboardAccessible } from './keyboard_accessible'; | ||
export { KuiScreenReaderOnly } from './screen_reader'; |
This file contains 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,20 @@ | ||
import { | ||
cloneElement, | ||
PropTypes, | ||
} from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
|
||
export const KuiScreenReaderOnly = ({ children }) => { | ||
const classes = classNames('kuiScreenReaderOnly', children.props.className); | ||
|
||
const props = Object.assign({}, children.props, { | ||
className: classes | ||
}); | ||
|
||
return cloneElement(children, props); | ||
}; | ||
|
||
KuiScreenReaderOnly.propTypes = { | ||
children: PropTypes.node | ||
}; |
35 changes: 35 additions & 0 deletions
35
ui_framework/components/accessibility/screen_reader.test.js
This file contains 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,35 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
|
||
import { KuiScreenReaderOnly } from './screen_reader'; | ||
|
||
describe('KuiScreenReaderOnly', () => { | ||
describe('adds an accessibility class to a child element', () => { | ||
test('when used with no props', () => { | ||
const $paragraph = render( | ||
<KuiScreenReaderOnly> | ||
<p> | ||
This paragraph is not visibile to sighted users but will be read by | ||
screenreaders. | ||
</p> | ||
</KuiScreenReaderOnly> | ||
); | ||
|
||
expect($paragraph) | ||
.toMatchSnapshot(); | ||
}); | ||
test('and combines other classNames (foo, bar) given as props on the child', () => { | ||
const $paragraph = render( | ||
<KuiScreenReaderOnly> | ||
<p className='foo bar'> | ||
This paragraph is not visibile to sighted users but will be read by | ||
screenreaders. | ||
</p> | ||
</KuiScreenReaderOnly> | ||
); | ||
|
||
expect($paragraph) | ||
.toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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
23 changes: 23 additions & 0 deletions
23
ui_framework/doc_site/src/views/accessibility/screen_reader.js
This file contains 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,23 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
KuiScreenReaderOnly, | ||
} from '../../../../components'; | ||
|
||
|
||
export default () => ( | ||
<div> | ||
<p> | ||
This is the first paragraph. It is visible to all. | ||
</p> | ||
<KuiScreenReaderOnly> | ||
<p> | ||
This is the second paragraph. It is hidden for sighted users but visible to screen readers. | ||
</p> | ||
</KuiScreenReaderOnly> | ||
<p> | ||
This is the third paragraph. It is visible to all. | ||
</p> | ||
</div> | ||
); | ||
|