From c0131c76b7330346978790bb7a5c44d653c5c5ce Mon Sep 17 00:00:00 2001 From: Jan Hassel Date: Tue, 21 Feb 2023 13:46:44 +0100 Subject: [PATCH 1/3] fix(toggle): make props.labelText optional --- .../src/components/Toggle/Toggle-test.js | 9 +++++-- .../react/src/components/Toggle/Toggle.js | 25 ++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/react/src/components/Toggle/Toggle-test.js b/packages/react/src/components/Toggle/Toggle-test.js index 8a7ec415028f..8d5eb958bc5d 100644 --- a/packages/react/src/components/Toggle/Toggle-test.js +++ b/packages/react/src/components/Toggle/Toggle-test.js @@ -92,10 +92,15 @@ describe('Toggle', () => { ).toBe(props.labelText); }); - it("doesn't render sideLabel if props.hideLabel and props['aria-labelledby'] are provided", () => { + it("doesn't render sideLabel if props.hideLabel and no props.labelText is provided", () => { const externalElementId = 'external-element-id'; wrapper.rerender( - + ); expect( diff --git a/packages/react/src/components/Toggle/Toggle.js b/packages/react/src/components/Toggle/Toggle.js index 5d950ba4a32a..e2bc83c5b684 100644 --- a/packages/react/src/components/Toggle/Toggle.js +++ b/packages/react/src/components/Toggle/Toggle.js @@ -47,8 +47,8 @@ export function Toggle({ const isSm = size === 'sm'; const sideLabel = hideLabel ? labelText : checked ? labelB : labelA; - const renderSideLabel = !(hideLabel && ariaLabelledby); - const LabelComponent = ariaLabelledby ? 'div' : 'label'; + const renderSideLabel = !(hideLabel && !labelText); + const LabelComponent = labelText ? 'label' : 'div'; const wrapperClasses = classNames( `${prefix}--toggle`, @@ -76,7 +76,7 @@ export function Toggle({
{ // the underlying