An open source design system that's fully customizable and agent ready
TypeScript
fix(core, richtext): no focus fade on text fields under a coarse pointer (#10611)
Christopher Chedeau619ffeb27cae
diff --git a/.changeset/text-field-focus-at-once.md b/.changeset/text-field-focus-at-once.mdnew file mode 100644index 0000000000..d98e7441de--- /dev/null+++ b/.changeset/text-field-focus-at-once.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+'@astryxdesign/richtext': patch+---++[fix] TextInput, TextArea, NumberInput, DateInput, DateRangeInput, DateTimeInput, TimeInput, Tokenizer, Typeahead, PowerSearch, ChatComposer and RichTextEditor: when the primary pointer is coarse (a phone or tablet), the focus look shows at once, with no fade, so a tapped field repaints once while the keyboard rises. With a fine primary pointer, such as a mouse, a click and the Tab key keep the fade. ChatComposer's focus depth also shows at once under reduced motion, as the other fields' focus look already does.++@vjeuxdiff --git a/docs/design/user-states.md b/docs/design/user-states.mdindex 191373429d..7ffb230103 100644--- a/docs/design/user-states.md+++ b/docs/design/user-states.md@@ -15,12 +15,15 @@ verified_by:packages/core/src/__tests__/PressedState.a11y.chromium.spec.ts,packages/core/src/CheckboxInput/CheckboxInput.test.tsx,packages/core/src/Collapsible/Collapsible.test.tsx,+ packages/core/src/Field/__tests__/TextFieldFocusTiming.interaction.browser.spec.ts,+ packages/core/src/Field/__tests__/textFieldFocusTiming.test.tsx,packages/core/src/Link/Link.test.tsx,packages/core/src/RadioList/RadioList.test.tsx,packages/core/src/SegmentedControl/SegmentedControl.test.tsx,packages/core/src/Slider/Slider.test.tsx,packages/core/src/Switch/Switch.test.tsx,packages/core/src/TabList/TabList.test.tsx,+ packages/richtext/src/RichTextEditor.focusTiming.test.tsx,]architecture: [architecture:interaction-modality, architecture:theme-tokens]components:@@ -136,15 +139,25 @@ actively responding. The decision is intentionally limited to the surfaces inthe matrix, preserves disabled behavior, and keeps an already-selected segment'sraised surface stable.+### DEC-2 — A tapped text field shows its focus look at once++**Reference:** `design:user-states/DEC-2`+**Decider:** `cixzhang`, 2026-11-07++A tapped text field shows its focus look at once, without a fade, matching the web's immediate focus look while preserving the performance: in Chromium, 2 repaints instead of 18; in Safari on iPhone the focus stall already hides most of the fade.++The device's primary pointer decides the timing, so Tab on a tablet with a hardware keyboard shows the focus look at once too.+## Open questions-None for this bounded pressed-state decision. Hover, focus, selection treatments-outside the selected-segment exception, and adoption by other components remain-outside this record's current claim.+None for the bounded pressed-state decision or DEC-2. Hover, focus beyond+DEC-2, selection treatments outside the selected-segment exception, and adoption+by other components remain outside this record's current claim.## Content boundaryThis file defines the approved cross-component pressed-state intent and its-bounded adoption matrix. Component implementations own selectors and event-mechanics; architecture records own interaction modality and token behavior;-tests and CI artifacts own current conformance evidence.+bounded adoption matrix, and a tapped text field's focus timing (DEC-2).+Component implementations own selectors and event mechanics; architecture+records own interaction modality and token behavior; tests and CI artifacts own+current conformance evidence.diff --git a/packages/core/src/Chat/ChatComposer.tsx b/packages/core/src/Chat/ChatComposer.tsxindex f34e03c86d..ac67fbeb71 100644--- a/packages/core/src/Chat/ChatComposer.tsx+++ b/packages/core/src/Chat/ChatComposer.tsx@@ -40,12 +40,12 @@ import {spacingVars,radiusVars,shadowVars,- durationVars,easeVars,borderVars,typeScaleVars,typographyVars,} from '../theme/tokens.stylex';+import {inputWrapperStyles} from '../Field/inputStyles.stylex';import {mergeProps} from '../utils';import {Icon} from '../Icon';import {ChatComposerInput} from './ChatComposerInput';@@ -172,7 +172,8 @@ const styles = stylex.create({default: 'text',':is(:disabled,[aria-disabled="true"])': 'default',},- transition: `box-shadow ${durationVars['--duration-fast']} ${easeVars['--ease-standard']}, border-color ${durationVars['--duration-fast']} ${easeVars['--ease-standard']}`,+ transitionProperty: 'box-shadow, border-color',+ transitionTimingFunction: easeVars['--ease-standard'],},header: {display: 'flex',@@ -573,6 +574,7 @@ export function ChatComposer(props: ChatComposerProps) {onBlurCapture={handleBodyBlurCapture}{...stylex.props(styles.body,+ inputWrapperStyles.textField,elevationStyles[elevation],hasKeyboardEditorFocus && focusOutlineStyles.focusWithin,density === 'compact' && styles.compact,diff --git a/packages/core/src/Chat/__tests__/ChatLayoutKeyboard.interaction.browser.spec.ts b/packages/core/src/Chat/__tests__/ChatLayoutKeyboard.interaction.browser.spec.tsindex c7a44f5780..41116b1e4d 100644--- a/packages/core/src/Chat/__tests__/ChatLayoutKeyboard.interaction.browser.spec.ts+++ b/packages/core/src/Chat/__tests__/ChatLayoutKeyboard.interaction.browser.spec.ts@@ -373,15 +373,18 @@ test.describe('under a mouse', () => {test('the dock comes down when the composer text loses focus', async ({page,}) => {- const {dock, editable} = await openChat(page);+ const {dock, editable, lift} = await openChat(page);await editable.focus();await showKeyboard(page);await waitForRest(dock);await editable.evaluate(el => (el as HTMLElement).blur());- // The hide starts from the blur; Mobile Safari reports it once the- // keyboard is down.- await waitForAnimation(dock);+ // Mobile Safari reports the keyboard gone once it is down, 0.47 to 0.5 s+ // after a blur on an iOS 26.2 simulator. The ride follows Chrome's slide+ // only, so until that report the dock stays above the keyboard. The wait+ // stands for most of that delay. Nothing moves the dock before the report+ // the test scripts, so a slow runner cannot fail this check.await page.waitForTimeout(440);+ expect(await dockY(dock)).toBeCloseTo(-lift, 0);await showKeyboard(page, 0);await waitForRest(dock);await page.waitForTimeout(100);diff --git a/packages/core/src/DateInput/DateInput.tsx b/packages/core/src/DateInput/DateInput.tsxindex a72c8f5806..14966bc858 100644--- a/packages/core/src/DateInput/DateInput.tsx+++ b/packages/core/src/DateInput/DateInput.tsx@@ -880,6 +880,7 @@ function PointerDateField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],// Disabled paint belongs to the disabled state only; a busy field// keeps its ordinary paint and shows the Spinner (spec:AST-085diff --git a/packages/core/src/DateInput/NativeDateField.tsx b/packages/core/src/DateInput/NativeDateField.tsxindex 0de2b5988f..7fd864f90c 100644--- a/packages/core/src/DateInput/NativeDateField.tsx+++ b/packages/core/src/DateInput/NativeDateField.tsx@@ -593,6 +593,7 @@ export function NativeDateField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],styles.wrapper,// Disabled paint belongs to the disabled state only; a busy fielddiff --git a/packages/core/src/DateInput/TouchDateField.tsx b/packages/core/src/DateInput/TouchDateField.tsxindex afc594f09a..1f17bcdbb5 100644--- a/packages/core/src/DateInput/TouchDateField.tsx+++ b/packages/core/src/DateInput/TouchDateField.tsx@@ -1322,6 +1322,7 @@ export function TouchDateField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],styles.wrapper,// Disabled paint belongs to the disabled state only; a busy fielddiff --git a/packages/core/src/DateRangeInput/DateRangeInput.tsx b/packages/core/src/DateRangeInput/DateRangeInput.tsxindex f111d900cb..2f219186e1 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.tsx+++ b/packages/core/src/DateRangeInput/DateRangeInput.tsx@@ -790,6 +790,7 @@ export function DateRangeInput({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],isEffectivelyDisabled && inputWrapperStyles.disabled,isEffectivelyDisabled && inputDisabledFocusStyles.withinRing,diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsxindex 3c15675e73..31f18d97e1 100644--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx@@ -1712,6 +1712,7 @@ function PointerDateTimeField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],styles.dateWrapper,isEffectivelyDisabled && inputWrapperStyles.disabled,@@ -1866,6 +1867,7 @@ function PointerDateTimeField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],styles.timeWrapper,isEffectivelyDisabled && inputWrapperStyles.disabled,diff --git a/packages/core/src/DateTimeInput/TouchDateTimeField.tsx b/packages/core/src/DateTimeInput/TouchDateTimeField.tsxindex 866ceebcbb..1f7db5d87f 100644--- a/packages/core/src/DateTimeInput/TouchDateTimeField.tsx+++ b/packages/core/src/DateTimeInput/TouchDateTimeField.tsx@@ -1297,6 +1297,7 @@ export function TouchDateTimeField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],styles.touchDateWrapper,isEffectivelyDisabled && inputWrapperStyles.disabled,@@ -1388,6 +1389,7 @@ export function TouchDateTimeField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],styles.touchTimeWrapper,isEffectivelyDisabled && inputWrapperStyles.disabled,diff --git a/packages/core/src/Field/PanelSearchInput.tsx b/packages/core/src/Field/PanelSearchInput.tsxindex db6d3fff73..1084b12b32 100644--- a/packages/core/src/Field/PanelSearchInput.tsx+++ b/packages/core/src/Field/PanelSearchInput.tsx@@ -279,6 +279,7 @@ export function PanelSearchInput({styles.field,isKeyboardFocus && styles.fieldKeyboardFocus,hasInputBox && inputWrapperStyles.base,+ hasInputBox && inputWrapperStyles.textField,fieldXstyle,)}><Icon icon="search" size="sm" color="secondary" xstyle={styles.icon} />diff --git a/packages/core/src/Field/__tests__/TextFieldFocusTiming.interaction.browser.spec.ts b/packages/core/src/Field/__tests__/TextFieldFocusTiming.interaction.browser.spec.tsnew file mode 100644index 0000000000..ff5cf64577--- /dev/null+++ b/packages/core/src/Field/__tests__/TextFieldFocusTiming.interaction.browser.spec.ts@@ -0,0 +1,299 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file TextFieldFocusTiming.interaction.browser.spec.ts+ * @input The built text field stories, tapped in the touch phone context, and+ * clicked and tabbed to in a mouse context of the same viewport+ * @output Proofs that a tapped text field shows its focus look at once, while+ * a mouse click and the keyboard still fade it in+ * @position Interaction evidence for the text field timing in+ * Field/inputStyles.stylex.ts, which ChatComposer and RichTextEditor share+ */++import {+ expect,+ test,+ type Browser,+ type Page,+} from '@astryxdesign/a11y-spec/playwright';+import {+ openStory,+ requireFrames,+ withStorybook,+} from '@astryxdesign/interaction-harness';++const storybook = withStorybook(test);++const FIELDS = [+ 'core-textinput--default',+ 'core-textarea--default',+ 'core-numberinput--default',+ 'core-tokenizer--default',+ 'core-typeahead--default',+ 'core-chatcomposer--simplest',+ 'richtext-richtexteditor--default',+] as const;++/** A text entry element, wherever it renders (a sheet's field included). */+const TEXT_ENTRY =+ ':is(input:not([type="hidden"]), textarea, [contenteditable="true"])';++/** The story's field: its text entry, or under a finger the button that opens its sheet. */+const ENTRY = `#storybook-root ${TEXT_ENTRY}`;+const TAP_TARGET = `#storybook-root :is(${TEXT_ENTRY}, button)`;++/** One read of the field's look, ms after the read at focus. */+interface LookSample {+ readonly t: number;+ readonly look: string;+}++/** The looks read from focus on, and the fade's duration, ms. */+interface FocusLook {+ readonly samples: ReadonlyArray<LookSample>;+ readonly durationMs: number;+}++/**+ * Records the field's look from the moment focus enters it. It reads once at+ * focus, then on each of the next 24 frames, with each read's time. The look+ * is the box-shadow and border colour of the element that fades them. A fade+ * shows in-between looks; a look shown at once shows only its last value.+ */+async function recordFocusLook(page: Page): Promise<void> {+ await page.evaluate(entrySelector => {+ const record: {samples: LookSample[]; durationMs: number} = {+ samples: [],+ durationMs: -1,+ };+ (window as unknown as {__focusLook: typeof record}).__focusLook = record;+ const onFocus = (event: FocusEvent) => {+ // Tab may pass other controls first: only the text entry counts.+ if (!(event.target as Element).matches(entrySelector)) {+ return;+ }+ document.removeEventListener('focusin', onFocus, true);+ let found = event.target as HTMLElement | null;+ while (+ found != null &&+ !/box-shadow|border-color/.test(+ getComputedStyle(found).transitionProperty,+ )+ ) {+ found = found.parentElement;+ }+ if (found == null) {+ return;+ }+ const wrapper = found;+ const duration = getComputedStyle(wrapper)+ .transitionDuration.split(',')[0]+ .trim();+ record.durationMs = duration.endsWith('ms')+ ? Number.parseFloat(duration)+ : Number.parseFloat(duration) * 1000;+ const start = performance.now();+ const read = () => {+ const style = getComputedStyle(wrapper);+ record.samples.push({+ t: performance.now() - start,+ look: `${style.boxShadow} | ${style.borderColor}`,+ });+ };+ read();+ let frames = 0;+ const tick = () => {+ read();+ if (++frames < 24) {+ requestAnimationFrame(tick);+ }+ };+ requestAnimationFrame(tick);+ };+ document.addEventListener('focusin', onFocus, true);+ }, TEXT_ENTRY);+}++/** The recorded looks, once all 25 reads are in. */+async function focusLook(page: Page): Promise<FocusLook> {+ const read = async () =>+ page.evaluate(+ () => (window as unknown as {__focusLook: FocusLook}).__focusLook,+ );+ await page+ .waitForFunction(+ () =>+ (window as unknown as {__focusLook: FocusLook}).__focusLook.samples+ .length >= 25,+ undefined,+ {timeout: 10_000},+ )+ .catch(async () => {+ const {samples} = await read();+ throw new Error(+ `the focus look was read ${samples.length} of 25 times in 10 s: focus never reached the text entry, or the page drew too few frames`,+ );+ });+ return read();+}++async function restingLook(page: Page): Promise<string> {+ return page+ .locator(ENTRY)+ .first()+ .evaluate(entry => {+ let wrapper = entry as HTMLElement | null;+ while (+ wrapper != null &&+ !/box-shadow|border-color/.test(+ getComputedStyle(wrapper).transitionProperty,+ )+ ) {+ wrapper = wrapper.parentElement;+ }+ if (wrapper == null) {+ return 'no wrapper';+ }+ const style = getComputedStyle(wrapper);+ return `${style.boxShadow} | ${style.borderColor}`;+ });+}++/** A mouse page of the touch page's viewport and scale. */+async function mousePage(browser: Browser, touch: Page): Promise<Page> {+ const viewport = touch.viewportSize() ?? {width: 390, height: 844};+ const context = await browser.newContext({+ viewport,+ hasTouch: false,+ isMobile: false,+ });+ return context.newPage();+}++for (const story of FIELDS) {+ test(`${story}: a tap shows the focus look at once`, async ({page}) => {+ await openStory(page, storybook(), story);+ const target = page.locator(TAP_TARGET).first();+ await expect(target).toBeVisible();+ const tapsAnEntry = await target.evaluate(+ (node, entry) => node.matches(entry),+ TEXT_ENTRY,+ );+ // A field that opens a sheet under a finger has no resting text entry.+ const rest = tapsAnEntry ? await restingLook(page) : null;+ await recordFocusLook(page);+ const box = await target.boundingBox();+ if (box == null) {+ throw new Error('no field box');+ }+ await page.touchscreen.tap(box.x + box.width / 2, box.y + box.height / 2);+ // Some engines leave a tapped contenteditable unfocused; the timing under+ // test is the same for any focus under this pointer.+ const focused = async () =>+ page.evaluate(+ entry => document.activeElement?.matches(entry) ?? false,+ TEXT_ENTRY,+ );+ if (tapsAnEntry && !(await focused())) {+ await target.focus();+ }+ if (!tapsAnEntry) {+ // The button opened the field's sheet: tap the sheet's own text entry.+ const field = page.locator(`${TEXT_ENTRY}:visible`).first();+ await expect(field).toBeInViewport();+ // Wait for the sheet to come to rest before aiming at its field.+ let fieldBox = await field.boundingBox();+ let rested = false;+ for (let i = 0; i < 40 && !rested; i++) {+ await page.waitForTimeout(100);+ const next = await field.boundingBox();+ rested = next != null && next.y === fieldBox?.y;+ fieldBox = next;+ }+ if (!rested) {+ throw new Error(+ `the sheet's text entry never came to rest in 4 s (last top ${fieldBox?.y})`,+ );+ }+ if (fieldBox == null) {+ throw new Error('no sheet field box');+ }+ await page.touchscreen.tap(+ fieldBox.x + fieldBox.width / 2,+ fieldBox.y + fieldBox.height / 2,+ );+ }+ await expect+ .poll(focused, {+ message: 'the tapped field passes focus to its text entry',+ timeout: 5_000,+ })+ .toBe(true);+ const {samples} = await focusLook(page);+ const last = samples[samples.length - 1].look;+ const looks = JSON.stringify({rest, samples});+ // The focus look is present: it differs from the resting look, or for a+ // sheet's field, it draws its focus ring.+ if (rest != null) {+ expect(last, looks).not.toBe(rest);+ } else {+ expect(last.split(' | ')[0], looks).not.toBe('none');+ }+ // And it shows at once: every read, from the one at focus on, is the+ // focus look.+ expect(+ samples.filter(sample => sample.look !== last),+ looks,+ ).toEqual([]);+ });++ test(`${story}: a mouse click and the Tab key still fade the focus look in`, async ({+ page,+ browser,+ }) => {+ for (const how of ['click', 'Tab'] as const) {+ const mouse = await mousePage(browser, page);+ await openStory(mouse, storybook(), story);+ const entry = mouse.locator(ENTRY).first();+ await expect(entry).toBeVisible();+ const rest = await restingLook(mouse);+ await recordFocusLook(mouse);+ if (how === 'click') {+ await entry.click();+ } else {+ // Tab from the top of the page until the text entry has focus.+ await mouse.evaluate(() =>+ (document.activeElement as HTMLElement | null)?.blur(),+ );+ for (let i = 0; i < 12; i++) {+ await mouse.keyboard.press('Tab');+ if (await entry.evaluate(node => node === document.activeElement)) {+ break;+ }+ }+ expect(+ await entry.evaluate(node => node === document.activeElement),+ ).toBe(true);+ }+ const {samples, durationMs} = await focusLook(mouse);+ const last = samples[samples.length - 1].look;+ const looks = JSON.stringify({how, rest, durationMs, samples});+ expect(last, looks).not.toBe(rest);+ expect(durationMs, looks).toBeGreaterThan(0);+ // Two frames inside the fade show it moving. Fewer means the page was+ // starved of frames, and that fails by name.+ const inFade = requireFrames(samples, {+ min: 2,+ during: `the ${durationMs} ms focus fade after a ${how}`,+ where: sample => sample.t > 0 && sample.t < durationMs,+ });+ // The fade: a frame shows a look between rest and the focus look.+ expect(+ inFade.filter(sample => sample.look !== rest && sample.look !== last)+ .length,+ looks,+ ).toBeGreaterThanOrEqual(1);+ await mouse.context().close();+ }+ });+}diff --git a/packages/core/src/Field/__tests__/textFieldFocusTiming.test.tsx b/packages/core/src/Field/__tests__/textFieldFocusTiming.test.tsxnew file mode 100644index 0000000000..4551b241d4--- /dev/null+++ b/packages/core/src/Field/__tests__/textFieldFocusTiming.test.tsx@@ -0,0 +1,243 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file textFieldFocusTiming.test.tsx+ * @input Every text field: TextInput, TextArea, NumberInput, the date and time+ * fields in each presentation, Tokenizer, Typeahead, PowerSearch,+ * PanelSearchInput with its input box, and ChatComposer+ * @output Proof that each field's focus look has no fade under a coarse+ * pointer, and keeps its fast fade under a fine pointer+ * @position Unit test for the text field timing in inputStyles.stylex.ts+ */++import {cleanup, render} from '@testing-library/react';+import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';+import * as stylex from '@stylexjs/stylex';+import type {ReactElement} from 'react';+import {inputWrapperStyles} from '../inputStyles.stylex';+import {PanelSearchInput} from '../PanelSearchInput';+import {TextInput} from '../../TextInput/TextInput';+import {TextArea} from '../../TextArea/TextArea';+import {NumberInput} from '../../NumberInput/NumberInput';+import {DateInput} from '../../DateInput/DateInput';+import {DateRangeInput} from '../../DateRangeInput/DateRangeInput';+import {DateTimeInput} from '../../DateTimeInput/DateTimeInput';+import {TimeInput} from '../../TimeInput/TimeInput';+import {Tokenizer} from '../../Tokenizer/Tokenizer';+import {Typeahead} from '../../Typeahead/Typeahead';+import type {SearchSource} from '../../Typeahead/types';+import {PowerSearch} from '../../PowerSearch/PowerSearch';+import {ChatComposer} from '../../Chat/ChatComposer';++// The sheet presentations measure their panes; jsdom has no ResizeObserver.+class MockResizeObserver {+ observe() {}+ unobserve() {}+ disconnect() {}+}++beforeEach(() => {+ vi.stubGlobal('ResizeObserver', MockResizeObserver);+});++afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();+});++const source: SearchSource = {search: async () => [], bootstrap: () => []};++/** A `transition-duration` the page declares for an element, by condition. */+interface Duration {+ readonly condition: string;+ readonly value: string;+}++/** Every `transition-duration` declared for the element's own classes. */+function durationsOf(element: Element): Duration[] {+ const classes = Array.from(element.classList, name => `.${name}`);+ const out: Duration[] = [];+ const visit = (rules: CSSRuleList, condition: string) => {+ for (const rule of Array.from(rules)) {+ if (rule instanceof CSSStyleRule) {+ const value = rule.style.getPropertyValue('transition-duration');+ if (value && classes.some(cls => rule.selectorText.startsWith(cls))) {+ out.push({condition, value: value.trim()});+ }+ continue;+ }+ const nested = (rule as CSSGroupingRule).cssRules;+ if (nested != null) {+ const own = (rule as CSSConditionRule).conditionText ?? '';+ visit(nested, [condition, own].filter(Boolean).join(' and '));+ }+ }+ };+ for (const sheet of Array.from(document.styleSheets)) {+ visit(sheet.cssRules, '');+ }+ return out;+}++/** The distinct focus durations a field's wrapper declares, per condition. */+function timingOf(element: Element) {+ const durations = durationsOf(element);+ const distinct = (list: Duration[]) =>+ [...new Set(list.map(d => d.value))].join(', ');+ return {+ fine: distinct(durations.filter(d => d.condition === '')),+ coarse: distinct(+ durations.filter(d => d.condition.includes('pointer: coarse')),+ ),+ reducedMotion: distinct(+ durations.filter(d => d.condition.includes('prefers-reduced-motion')),+ ),+ };+}++const TEXT_FIELD_CLASSES = (+ stylex.props(inputWrapperStyles.textField).className ?? ''+).split(/\s+/);++/** The elements that carry the text field timing, in render order. */+function textFieldWrappers(container: HTMLElement): HTMLElement[] {+ return Array.from(container.querySelectorAll<HTMLElement>('*')).filter(+ element =>+ TEXT_FIELD_CLASSES.every(name => element.classList.contains(name)),+ );+}++const FIELDS: ReadonlyArray<readonly [string, () => ReactElement]> = [+ ['TextInput', () => <TextInput label="Name" value="" onChange={() => {}} />],+ [+ 'TextArea',+ () => <TextArea label="Description" value="" onChange={() => {}} />,+ ],+ [+ 'NumberInput',+ () => <NumberInput label="Quantity" value={null} onChange={() => {}} />,+ ],+ [+ 'DateInput, popover',+ () => <DateInput label="Date" presentation="popover" onChange={() => {}} />,+ ],+ [+ 'DateInput, bottom sheet',+ () => (+ <DateInput label="Date" presentation="bottom-sheet" onChange={() => {}} />+ ),+ ],+ [+ 'DateInput, native',+ () => <DateInput label="Date" presentation="native" onChange={() => {}} />,+ ],+ [+ 'DateRangeInput',+ () => <DateRangeInput label="Range" value={null} onChange={() => {}} />,+ ],+ [+ 'DateTimeInput, popover',+ () => (+ <DateTimeInput+ label="Meeting time"+ presentation="popover"+ onChange={() => {}}+ />+ ),+ ],+ [+ 'DateTimeInput, bottom sheet',+ () => (+ <DateTimeInput+ label="Meeting time"+ presentation="bottom-sheet"+ onChange={() => {}}+ />+ ),+ ],+ [+ 'TimeInput, popover',+ () => <TimeInput label="Time" presentation="popover" onChange={() => {}} />,+ ],+ [+ 'TimeInput, bottom sheet',+ () => (+ <TimeInput label="Time" presentation="bottom-sheet" onChange={() => {}} />+ ),+ ],+ [+ 'Tokenizer',+ () => (+ <Tokenizer+ label="Members"+ searchSource={source}+ value={[]}+ onChange={() => {}}+ />+ ),+ ],+ [+ 'Typeahead',+ () => (+ <Typeahead+ label="Assignee"+ searchSource={source}+ value={null}+ onChange={() => {}}+ />+ ),+ ],+ [+ 'PowerSearch',+ () => (+ <PowerSearch+ config={{+ name: 'Search',+ fields: [+ {+ key: 'title',+ label: 'Title',+ defaultOperator: 'contains',+ operators: [+ {key: 'contains', label: 'contains', value: {type: 'string'}},+ ],+ },+ ],+ }}+ filters={[]}+ onChange={() => {}}+ />+ ),+ ],+ ['ChatComposer', () => <ChatComposer onSubmit={() => {}} />],+ [+ 'PanelSearchInput with its input box',+ () => (+ <PanelSearchInput+ label="Search"+ clearLabel="Clear search"+ value=""+ onValueChange={() => {}}+ hasInputBox+ />+ ),+ ],+];++describe('text field focus timing', () => {+ it.each(FIELDS)(+ '%s shows its focus look at once under a coarse pointer or reduced motion, and fades it under a fine pointer',+ (_name, renderField) => {+ const {container} = render(renderField());+ const wrappers = textFieldWrappers(container);+ expect(wrappers.length).toBeGreaterThan(0);+ for (const wrapper of wrappers) {+ const timing = timingOf(wrapper);+ expect(timing.coarse).toBe('0s');+ expect(timing.reducedMotion).toBe('0s');+ expect(timing.fine).not.toBe('');+ expect(timing.fine).not.toBe('0s');+ }+ },+ );+});diff --git a/packages/core/src/Field/inputStyles.stylex.ts b/packages/core/src/Field/inputStyles.stylex.tsindex f871074aae..2a37007930 100644--- a/packages/core/src/Field/inputStyles.stylex.ts+++ b/packages/core/src/Field/inputStyles.stylex.ts@@ -3,7 +3,8 @@/*** @file inputStyles.stylex.ts* @input Uses theme tokens (color, spacing, radius, shadow, transition)- * @output Exports shared input wrapper appearance styles+ * @output Exports shared input wrapper appearance styles, and the text field+ * timing that shows the focus look at once under a coarse pointer* @position Shared styles consumed by TextInput, TextArea, NumberInput, DateInput,* TimeInput, Selector, Typeahead, and Tokenizer*@@ -78,6 +79,15 @@ export const inputWrapperStyles = stylex.create({// Suppress the base hover ring — a disabled control must not react to hover.boxShadow: 'none',},+ // Text fields apply this after `base`. A tap on one raises the keyboard,+ // and a fade would repaint the field on each frame of that rise.+ textField: {+ transitionDuration: {+ default: durationVars['--duration-fast'],+ '@media (prefers-reduced-motion: reduce)': '0s',+ '@media (pointer: coarse)': '0s',+ },+ },});/**diff --git a/packages/core/src/NumberInput/NumberInput.tsx b/packages/core/src/NumberInput/NumberInput.tsxindex 54bfd1cae9..a400173d6f 100644--- a/packages/core/src/NumberInput/NumberInput.tsx+++ b/packages/core/src/NumberInput/NumberInput.tsx@@ -1194,6 +1194,7 @@ export function NumberInput({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,hasNumberSteppers && styles.wrapperWithNumberSteppers,sizeStyles[size],diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsxindex 6896bd8da5..642ca21e72 100644--- a/packages/core/src/PowerSearch/PowerSearch.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.tsx@@ -1534,6 +1534,7 @@ export function PowerSearch({aria-disabled={isDisabled ? true : undefined}{...stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sheetTriggerStyles.wrapper,filters.length > 0 && sheetTriggerStyles.wrapperWithTokens,sheetTriggerSizeStyles[size],diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsxindex 31a02db4eb..a58970bfbb 100644--- a/packages/core/src/TextArea/TextArea.tsx+++ b/packages/core/src/TextArea/TextArea.tsx@@ -626,6 +626,7 @@ export function TextArea({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,isDisabled && inputWrapperStyles.disabled,isDisabled && inputDisabledFocusStyles.ring,diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsxindex 3cfa41aab4..9f64e3f571 100644--- a/packages/core/src/TextInput/TextInput.tsx+++ b/packages/core/src/TextInput/TextInput.tsx@@ -501,6 +501,7 @@ export function TextInput({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],isDisabled && inputWrapperStyles.disabled,isDisabled && inputDisabledFocusStyles.ring,diff --git a/packages/core/src/TimeInput/TimeInput.tsx b/packages/core/src/TimeInput/TimeInput.tsxindex 20ddc3f06e..db76713b69 100644--- a/packages/core/src/TimeInput/TimeInput.tsx+++ b/packages/core/src/TimeInput/TimeInput.tsx@@ -785,6 +785,7 @@ function TimeField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],isDisabled && inputWrapperStyles.disabled,isDisabled && inputDisabledFocusStyles.withinRing,diff --git a/packages/core/src/TimeInput/TouchTimeField.tsx b/packages/core/src/TimeInput/TouchTimeField.tsxindex 52938dfb7a..abd414a9e2 100644--- a/packages/core/src/TimeInput/TouchTimeField.tsx+++ b/packages/core/src/TimeInput/TouchTimeField.tsx@@ -381,6 +381,7 @@ export function TouchTimeField({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,sizeStyles[size],isDisabled && inputWrapperStyles.disabled,isDisabled && inputDisabledFocusStyles.withinRing,diff --git a/packages/core/src/Tokenizer/Tokenizer.tsx b/packages/core/src/Tokenizer/Tokenizer.tsxindex c539f4c412..695593e0e5 100644--- a/packages/core/src/Tokenizer/Tokenizer.tsx+++ b/packages/core/src/Tokenizer/Tokenizer.tsx@@ -1492,6 +1492,7 @@ export function Tokenizer<T extends SearchableItem>({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,value.length > 0 && styles.wrapperWithTokens,isTruncated ? truncatedSizeStyles[size] : sizeStyle,@@ -1719,6 +1720,7 @@ export function Tokenizer<T extends SearchableItem>({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,styles.sheetField,isDisabled && styles.sheetFieldDisabled,@@ -1898,6 +1900,7 @@ export function Tokenizer<T extends SearchableItem>({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,value.length > 0 && styles.wrapperWithTokens,placeholderSizeStyle,diff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsxindex a258302412..9f2a7bfb1d 100644--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx@@ -3079,7 +3079,11 @@ describe('Tokenizer sheet draft, Save and dismissal (FR18, FR23, FR24, FR26, FR2const input = screen.getByLabelText('Search Tags');const field = input.parentElement!;for (const name of atoms(- stylex.props(inputWrapperStyles.base, own.field).className,+ stylex.props(+ inputWrapperStyles.base,+ inputWrapperStyles.textField,+ own.field,+ ).className,)) {expect(field).toHaveClass(name);}diff --git a/packages/core/src/Typeahead/Typeahead.tsx b/packages/core/src/Typeahead/Typeahead.tsxindex 16e81e3de3..5a55f9159e 100644--- a/packages/core/src/Typeahead/Typeahead.tsx+++ b/packages/core/src/Typeahead/Typeahead.tsx@@ -673,6 +673,7 @@ export function Typeahead<T extends SearchableItem>({themeProps('typeahead', {size, status: status?.type}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,sizeStyle,status && inputStatusBorderStyles[status.type],diff --git a/packages/richtext/src/RichTextEditor.focusTiming.test.tsx b/packages/richtext/src/RichTextEditor.focusTiming.test.tsxnew file mode 100644index 0000000000..0c22a245ab--- /dev/null+++ b/packages/richtext/src/RichTextEditor.focusTiming.test.tsx@@ -0,0 +1,75 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file RichTextEditor.focusTiming.test.tsx+ * @input RichTextEditor, and the text field timing it shares with Core's text+ * fields+ * @output Proof that the editor's field shows its focus look at once under a+ * coarse pointer or reduced motion, and fades it under a fine pointer+ * @position Unit test for RichTextEditor's use of+ * `inputWrapperStyles.textField`+ */++import {cleanup, render} from '@testing-library/react';+import {afterEach, describe, expect, it} from 'vitest';+import * as stylex from '@stylexjs/stylex';+import {inputWrapperStyles} from '@astryxdesign/core/Field';+import {RichTextEditor} from './RichTextEditor';++afterEach(() => {+ cleanup();+});++/** Every `transition-duration` declared for the element's own classes. */+function durationsOf(element: Element) {+ const classes = Array.from(element.classList, name => `.${name}`);+ const out: Array<{condition: string; value: string}> = [];+ const visit = (rules: CSSRuleList, condition: string) => {+ for (const rule of Array.from(rules)) {+ if (rule instanceof CSSStyleRule) {+ const value = rule.style.getPropertyValue('transition-duration');+ if (value && classes.some(cls => rule.selectorText.startsWith(cls))) {+ out.push({condition, value: value.trim()});+ }+ continue;+ }+ const nested = (rule as CSSGroupingRule).cssRules;+ if (nested != null) {+ const own = (rule as CSSConditionRule).conditionText ?? '';+ visit(nested, [condition, own].filter(Boolean).join(' and '));+ }+ }+ };+ for (const sheet of Array.from(document.styleSheets)) {+ visit(sheet.cssRules, '');+ }+ return out;+}++describe('RichTextEditor focus timing', () => {+ it('shows its focus look at once under a coarse pointer or reduced motion, and fades it under a fine pointer', () => {+ const {container} = render(<RichTextEditor label="Notes" />);+ const textField = (+ stylex.props(inputWrapperStyles.textField).className ?? ''+ ).split(/\s+/);+ const wrappers = Array.from(+ container.querySelectorAll<HTMLElement>('*'),+ ).filter(element =>+ textField.every(name => element.classList.contains(name)),+ );+ expect(wrappers).toHaveLength(1);+ const durations = durationsOf(wrappers[0]);+ const values = (match: (condition: string) => boolean) => [+ ...new Set(durations.filter(d => match(d.condition)).map(d => d.value)),+ ];+ expect(values(condition => condition.includes('pointer: coarse'))).toEqual([+ '0s',+ ]);+ expect(+ values(condition => condition.includes('prefers-reduced-motion')),+ ).toEqual(['0s']);+ const fine = values(condition => condition === '');+ expect(fine).toHaveLength(1);+ expect(fine[0]).not.toBe('0s');+ });+});diff --git a/packages/richtext/src/RichTextEditor.tsx b/packages/richtext/src/RichTextEditor.tsxindex 66a2a5579b..e1df3e0574 100644--- a/packages/richtext/src/RichTextEditor.tsx+++ b/packages/richtext/src/RichTextEditor.tsx@@ -662,6 +662,7 @@ export const RichTextEditor = function RichTextEditor({}),stylex.props(inputWrapperStyles.base,+ inputWrapperStyles.textField,styles.wrapper,// Only disabled is dimmed, matching TextArea: a read-only editor// keeps full-opacity text and stays keyboard-reachable.