From 5f94786e60ea76e184222e98287e6200bb51a97c Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Fri, 21 Jul 2023 11:33:45 +1000 Subject: [PATCH] Revert "Toggle switch a11y take3 (#3510)" This reverts commit bdbcfd151d00a7995b07f57e2b37468af0bd0ee5. --- .changeset/cool-hornets-call.md | 7 ---- 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(+), 52 deletions(-) delete mode 100644 .changeset/cool-hornets-call.md diff --git a/.changeset/cool-hornets-call.md b/.changeset/cool-hornets-call.md deleted file mode 100644 index 81fd3401543..00000000000 --- a/.changeset/cool-hornets-call.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@primer/react': minor ---- - -Implement accessibility audit feedback for ToggleSwitch - - 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 b149cda4847..20a23ed556e 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' @@ -251,8 +252,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 @@ -265,11 +265,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'}