An open source design system that's fully customizable and agent ready
TypeScript
fix(Selector): the open list honors Reduce Motion (#9611)
Cindy Zhange4f5cad14ff1
diff --git a/.changeset/selector-list-reduced-motion.md b/.changeset/selector-list-reduced-motion.mdnew file mode 100644index 0000000000..3a4bf24106--- /dev/null+++ b/.changeset/selector-list-reduced-motion.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A Selector's option list no longer fades in when Reduce Motion is on with a mouse or trackpad; it appears at once. On a touch screen it uses the shared Reduce Motion cross-fade.++@cixzhangdiff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsxindex 78e00f7d90..2a6acdf22a 100644--- a/packages/core/src/Selector/Selector.tsx+++ b/packages/core/src/Selector/Selector.tsx@@ -46,6 +46,7 @@ import {} from '../Field';import {Divider} from '../Divider';import {layerAnimations} from '../Layer/layerAnimations.stylex';+import {reducedMotionFadeConsts} from '../motion/reducedMotion.stylex';import {useKeepLayerOpenProps, type LayerPlacement} from '../Layer/useLayer';import {InternalInputClearButton} from '../Field/InputClearButton';import {Spinner} from '../Spinner';@@ -358,7 +359,21 @@ const styles = stylex.create({paddingBlock: spacingVars['--spacing-1'],paddingInline: spacingVars['--spacing-1'],opacity: 1,- transition: `opacity ${durationVars['--duration-fast']}`,+ // Under Reduce Motion the list appears at once on a fine pointer, and+ // takes the shared cross-fade on a coarse one.+ transitionProperty: 'opacity',+ transitionDuration: {+ default: durationVars['--duration-fast'],+ '@media (prefers-reduced-motion: reduce) and (pointer: coarse)':+ reducedMotionFadeConsts.duration,+ '@media (prefers-reduced-motion: reduce) and (not (pointer: coarse))':+ '0s',+ },+ transitionTimingFunction: {+ default: 'ease',+ '@media (prefers-reduced-motion: reduce) and (pointer: coarse)':+ reducedMotionFadeConsts.easing,+ },},dropdownInput: {// The input trigger's text inset includes its border. Mirror that extra@@ -384,7 +399,8 @@ const styles = stylex.create({},dropdownHidden: {opacity: 0,- transition: 'none',+ // A longhand: the shorthand would lose to the list's longhands.+ transitionProperty: 'none',},// Popover container (for anchor positioning)diff --git a/packages/core/src/Selector/__tests__/SelectorReducedMotion.a11y.chromium.spec.ts b/packages/core/src/Selector/__tests__/SelectorReducedMotion.a11y.chromium.spec.tsnew file mode 100644index 0000000000..91b49da575--- /dev/null+++ b/packages/core/src/Selector/__tests__/SelectorReducedMotion.a11y.chromium.spec.ts@@ -0,0 +1,64 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @pr-a11y scope ^(packages/core/src/Selector/|packages/core/src/motion/reducedMotion|apps/storybook/stories/Selector\.stories)++/**+ * @file SelectorReducedMotion.a11y.chromium.spec.ts+ * @input Storybook story core-selector--default+ * @output The open list's opacity transition in a real browser: under Reduce+ * Motion it completes at once on a fine pointer and takes the 200 ms shared+ * cross-fade on a coarse one; with no preference it keeps its short fade.+ * @position Real-browser check: jsdom evaluates no media queries.+ */++import {expect, test, type Page} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;++test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});++test.afterAll(async () => {+ await storybook?.close();+});++async function listTransition(page: Page) {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-selector--default&viewMode=story&args=presentation:popover`,+ {waitUntil: 'load'},+ );+ await page.getByRole('combobox').first().click();+ const listbox = page.getByRole('listbox');+ await expect(listbox).toBeVisible();+ return listbox.evaluate(element => {+ const style = getComputedStyle(element);+ return {+ property: style.transitionProperty,+ duration: style.transitionDuration,+ };+ });+}++test.describe('fine pointer', () => {+ test.use({isMobile: false, hasTouch: false});++ test('under Reduce Motion the list appears at once', async ({page}) => {+ await page.emulateMedia({reducedMotion: 'reduce'});+ const transition = await listTransition(page);+ expect(transition.duration).toBe('0s');+ });++ test('with no preference the list keeps its short fade', async ({page}) => {+ await page.emulateMedia({reducedMotion: 'no-preference'});+ const transition = await listTransition(page);+ expect(transition.property).toBe('opacity');+ expect(transition.duration).not.toBe('0s');+ });+});