From 12e92b72fc5e94c8a5298adf1f5ed299b9a3b4c6 Mon Sep 17 00:00:00 2001 From: Siddharth Kshetrapal Date: Tue, 4 Jul 2023 14:21:02 +0200 Subject: [PATCH 1/2] Revert "Address ToggleSwitch a11y feedback (#3251) (#3433)" This reverts commit cd086ae6df0b0dd1d18c29898c0841a83b857698. --- .changeset/two-cycles-provide.md | 5 --- e2e/components/ToggleSwitch.test.ts | 5 --- src/ToggleSwitch/ToggleSwitch.tsx | 8 ++-- src/__tests__/ToggleSwitch.test.tsx | 35 +++++----------- .../__snapshots__/ToggleSwitch.test.tsx.snap | 41 +++++++++++++------ 5 files changed, 44 insertions(+), 50 deletions(-) delete mode 100644 .changeset/two-cycles-provide.md diff --git a/.changeset/two-cycles-provide.md b/.changeset/two-cycles-provide.md deleted file mode 100644 index 803bbd43fcb..00000000000 --- a/.changeset/two-cycles-provide.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@primer/react': minor ---- - -Address ToggleSwitch accessibility feedback diff --git a/e2e/components/ToggleSwitch.test.ts b/e2e/components/ToggleSwitch.test.ts index bde4521a25c..33ed880d336 100644 --- a/e2e/components/ToggleSwitch.test.ts +++ b/e2e/components/ToggleSwitch.test.ts @@ -30,11 +30,6 @@ test.describe('ToggleSwitch', () => { 'color-contrast': { enabled: theme !== 'dark_dimmed', }, - - // the 'default' preview does not associate a label with the button - 'button-name': { - enabled: false, - }, }, }) }) diff --git a/src/ToggleSwitch/ToggleSwitch.tsx b/src/ToggleSwitch/ToggleSwitch.tsx index 6606f5edc1c..851757d9bab 100644 --- a/src/ToggleSwitch/ToggleSwitch.tsx +++ b/src/ToggleSwitch/ToggleSwitch.tsx @@ -7,6 +7,7 @@ import Text from '../Text' import {get} from '../constants' import {useProvidedStateOrCreate} from '../hooks' import sx, {BetterSystemStyleObject, SxProp} from '../sx' +import VisuallyHidden from '../_VisuallyHidden' import {CellAlignment} from '../DataTable/column' const TRANSITION_DURATION = '80ms' @@ -253,8 +254,7 @@ const ToggleSwitch: React.FC> = ({ fontSize={size === 'small' ? 0 : 1} mx={2} aria-hidden="true" - sx={{position: 'relative', cursor: 'pointer'}} - onClick={handleToggleClick} + sx={{position: 'relative'}} > On @@ -267,11 +267,13 @@ const ToggleSwitch: React.FC> = ({ onClick={handleToggleClick} aria-labelledby={ariaLabelledby} aria-describedby={ariaDescribedby} - aria-pressed={isOn} + aria-checked={isOn} + role="switch" checked={isOn} size={size} disabled={!acceptsInteraction} > + {isOn ? 'On' : 'Off'}