From 24d02707cb8f236371dee6076fa9deae7993e95c Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Fri, 21 Jul 2023 10:29:32 +1000 Subject: [PATCH 01/10] Add deprecated notice and run console warn only in DEV --- src/PageLayout/PageLayout.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/PageLayout/PageLayout.tsx b/src/PageLayout/PageLayout.tsx index 6a81204d3a0..398ee9915da 100644 --- a/src/PageLayout/PageLayout.tsx +++ b/src/PageLayout/PageLayout.tsx @@ -482,6 +482,9 @@ Content.displayName = 'PageLayout.Content' // PageLayout.Pane export type PageLayoutPaneProps = { + /** + * @deprecated position the pane by ordering your markup instead. + */ position?: keyof typeof panePositions | ResponsiveValue /** * @deprecated Use the `position` prop with a responsive value instead. @@ -563,12 +566,10 @@ const Pane = React.forwardRef { - if (responsivePosition !== undefined) { - // eslint-disable-next-line no-console - console.warn( - 'The `position` prop will be removed on the next major version. You should order your markup as you want it to render instead.', - ) - } + warning( + responsivePosition !== undefined, + 'The `position` prop will be removed on the next major version. You should order your markup as you want it to render instead.', + ) // Combine position and positionWhenNarrow for backwards compatibility const positionProp = From 6cb8bbe4ef147a025297fdfd4170ad13b615a881 Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Fri, 21 Jul 2023 11:13:20 +1000 Subject: [PATCH 02/10] run when the env is not test --- src/PageLayout/PageLayout.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/PageLayout/PageLayout.tsx b/src/PageLayout/PageLayout.tsx index 398ee9915da..66df4cd3293 100644 --- a/src/PageLayout/PageLayout.tsx +++ b/src/PageLayout/PageLayout.tsx @@ -566,10 +566,17 @@ const Pane = React.forwardRef { - warning( - responsivePosition !== undefined, - 'The `position` prop will be removed on the next major version. You should order your markup as you want it to render instead.', - ) + if (__DEV__ && process.env.NODE_ENV !== 'test') { + // We don't want these warnings to show up on tests because it fails the tests (at dotcom) due to not extecting a warning. + // Practically, this is not a conditional hook, it is just making sure this hook runs only on DEV not PROD. + // eslint-disable-next-line react-hooks/rules-of-hooks + React.useEffect(() => { + warning( + responsivePosition !== undefined, + 'The `position` prop will be removed on the next major version. You should order your markup as you want it to render instead.', + ) + }, [responsivePosition]) + } // Combine position and positionWhenNarrow for backwards compatibility const positionProp = From 5f94786e60ea76e184222e98287e6200bb51a97c Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Fri, 21 Jul 2023 11:33:45 +1000 Subject: [PATCH 03/10] 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'}