Skip to content
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

feat(switch): accessibility improvements for the switch component #1496

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions components/switch/src/switch/__tests__/switch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@ describe('<Switch />', () => {

expect(onKeyDown).toHaveBeenCalledTimes(1)
})

it('renders the switch with aria label', () => {
const ariaLabel = 'test switch'
render(
<Switch
aria-label={ariaLabel}
name="foo"
value="bar"
checked={false}
/>
)
expect(screen.getAllByLabelText(ariaLabel)).toHaveLength(1)
})
})
4 changes: 2 additions & 2 deletions components/switch/src/switch/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Switch extends Component {

render() {
const {
ariaLabel,
'aria-label': ariaLabel,
checked,
className,
disabled,
Expand Down Expand Up @@ -172,7 +172,7 @@ Switch.defaultProps = {

Switch.propTypes = {
/** Sets an aria-label attribute on the input */
ariaLabel: PropTypes.string,
'aria-label': PropTypes.string,
checked: PropTypes.bool,
className: PropTypes.string,
dataTest: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion components/switch/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SwitchProps {
/**
* Sets an aria-label attribute on the input
*/
ariaLabel?: string
'aria-label'?: string
checked?: boolean
className?: string
dataTest?: string
Expand Down
Loading