From bf9927a204d56e688ee64cbff021e249f7f94b5e Mon Sep 17 00:00:00 2001 From: Diana Nanyanzi Date: Mon, 29 Apr 2024 07:46:52 +0300 Subject: [PATCH] feat: add optional aria-label prop to switch component --- .../switch/src/switch/__tests__/switch.test.js | 13 +++++++++++++ components/switch/src/switch/switch.js | 4 ++-- components/switch/types/index.d.ts | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/switch/src/switch/__tests__/switch.test.js b/components/switch/src/switch/__tests__/switch.test.js index 172691e8d4..2d1d6a036c 100644 --- a/components/switch/src/switch/__tests__/switch.test.js +++ b/components/switch/src/switch/__tests__/switch.test.js @@ -28,4 +28,17 @@ describe('', () => { expect(onKeyDown).toHaveBeenCalledTimes(1) }) + + it('renders the switch with aria label', () => { + const ariaLabel = 'test switch' + render( + + ) + expect(screen.getAllByLabelText(ariaLabel)).toHaveLength(1) + }) }) diff --git a/components/switch/src/switch/switch.js b/components/switch/src/switch/switch.js index 31c273a2dc..a53cf7cc35 100644 --- a/components/switch/src/switch/switch.js +++ b/components/switch/src/switch/switch.js @@ -47,7 +47,7 @@ class Switch extends Component { render() { const { - ariaLabel, + 'aria-label': ariaLabel, checked, className, disabled, @@ -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, diff --git a/components/switch/types/index.d.ts b/components/switch/types/index.d.ts index fbd94350a4..3a18fba501 100644 --- a/components/switch/types/index.d.ts +++ b/components/switch/types/index.d.ts @@ -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