From 0b336dd781dcaef09538c6bf2f426435f79d32d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arma=C4=9Fan?= Date: Tue, 13 Jun 2023 07:39:52 +1000 Subject: [PATCH] Revert "Address ToggleSwitch a11y feedback (#3251)" This reverts commit 580f1650146f35d6af509704a0ee2b203a50812c. --- .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'}