Skip to content

Commit

Permalink
feat: add optional aria-label prop to switch component
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Apr 29, 2024
1 parent 0bf3520 commit bf9927a
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 bf9927a

Please sign in to comment.