Skip to content

Commit

Permalink
Merge pull request #1496 from dhis2/LIBS-572/switch-accessibility
Browse files Browse the repository at this point in the history
feat(switch): accessibility improvements for the switch component
  • Loading branch information
kabaros authored Jun 3, 2024
2 parents d8aea01 + bf9927a commit 6d499cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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

0 comments on commit 6d499cc

Please sign in to comment.