An open source design system that's fully customizable and agent ready
TypeScript
feat(inputs)!: FR10 prop targets for Typeahead, Tokenizer, CheckboxList, RadioList, Slider (#7339)
Cindy Zhangda6f47086a11
diff --git a/.changeset/field-input-styling-fieldroot.md b/.changeset/field-input-styling-fieldroot.mdnew file mode 100644index 0000000000..5f1e8a2000--- /dev/null+++ b/.changeset/field-input-styling-fieldroot.md@@ -0,0 +1,22 @@+---+'@astryxdesign/core': minor+'@astryxdesign/cli': minor+---++[breaking] Typeahead, Tokenizer, CheckboxList, RadioList, and Slider no longer accept root `xstyle`, `className`, or `style`. Style the field with `containerXstyle`/`containerClassName`/`containerStyle` (the Field box; no effect inside InputGroup or a `horizontal-labels` FormLayout) and the visual control box with `controlXstyle`/`controlClassName`/`controlStyle`. Base props now reach the primary semantic control: the combobox input for Typeahead and Tokenizer, the `role="group"`/`role="radiogroup"` element for CheckboxList and RadioList, and the `role="slider"` thumb for Slider (the `role="group"` control in range mode). A caller `aria-describedby` is kept alongside the field's own description and status, on these components and on TextInput, TextArea, and NumberInput, which previously dropped it. CLI templates use the new props.++Migration: rename root `xstyle`/`className`/`style` to the part they styled before: `containerXstyle`/`containerClassName`/`containerStyle` on all five components, except a Typeahead inside InputGroup, whose root styling painted the control surface and moves to `controlXstyle`/`controlClassName`/`controlStyle`. The release's `astryx upgrade` codemod, `migrate-field-input-styling`, performs these renames on JSX usage.++Not rewritten by the codemod, so update by hand:+- `ref` and `id`, plus `data-*` (except Typeahead and Tokenizer `data-testid`, which marked the control surface), `aria-*`, and DOM event handlers such as `onClick`, previously landed on the outer Field (or were dropped by RadioList and Slider). They now land on the primary semantic control. Update code that measured, queried, or listened on the outer field, and wrap the component in your own element when you need an outer boundary.+- Typeahead and Tokenizer refs are now `HTMLInputElement`.+- A consumer `onKeyDown` on Typeahead or Tokenizer still runs after the built-in key handling, cannot cancel it, and still fires for keys on the clear button and tokens; for keys on the input it now runs on the combobox input itself.+- RadioList and Slider used to drop DOM event handlers; they now run after the component's own handling, so a Slider `onPointerDown`, `onKeyDown`, `onFocus`, or `onBlur` that never fired before now fires (on the thumb, or on the group in range mode).+- Tokenizer's `onFocus`/`onBlur` keep their meaning: focus entering or leaving the field.+- Styling passed through a wrapper's own props or a spread is not rewritten and now fails type-checking at that callsite.++Untyped callers get a development warning and the value is ignored.++From #5656 by @harjothkhara.++@cixzhangdiff --git a/apps/sandbox/src/app/(raw)/pages/mobile-prototypes/prototypes.tsx b/apps/sandbox/src/app/(raw)/pages/mobile-prototypes/prototypes.tsxindex a81a151df0..ca7cffead5 100644--- a/apps/sandbox/src/app/(raw)/pages/mobile-prototypes/prototypes.tsx+++ b/apps/sandbox/src/app/(raw)/pages/mobile-prototypes/prototypes.tsx@@ -1029,7 +1029,7 @@ function MultiSelectorDemo() {isLabelHiddenvalue={draft}onChange={setDraft}- xstyle={s.flushSheetCheckList}+ containerXstyle={s.flushSheetCheckList}hasDividers>{LABELS.map(l => (<CheckboxListItemdiff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsxindex 79b76034a4..a30a6efcfb 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsx+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsx@@ -322,7 +322,7 @@ function MicroInteractionsCard() {onChange={setSliderValue}min={0}max={100}- xstyle={styles.maxW300}+ containerXstyle={styles.maxW300}/></VStack>diff --git a/packages/cli/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx b/packages/cli/assets/templates/blocks/components/Slider/SliderFormattedValue.tsxindex ca35a3bfa7..9a0925fd12 100644--- a/packages/cli/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx+++ b/packages/cli/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx@@ -9,7 +9,7 @@ export default function SliderFormattedValue() {const [value, setValue] = useState(72);return (<Slider- style={{width: 300}}+ containerStyle={{width: 300}}label="Temperature"value={value}onChange={setValue}diff --git a/packages/cli/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx b/packages/cli/assets/templates/blocks/components/Slider/SliderRangeSlider.tsxindex d453f1196c..c3b35e1b4c 100644--- a/packages/cli/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx+++ b/packages/cli/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx@@ -12,7 +12,7 @@ export default function SliderRangeSlider() {label="Price range"value={value}onChange={setValue}- style={{width: 300}}+ containerStyle={{width: 300}}/>);}diff --git a/packages/cli/assets/templates/blocks/components/Slider/SliderShowcase.tsx b/packages/cli/assets/templates/blocks/components/Slider/SliderShowcase.tsxindex 620309eafa..ec78578a0f 100644--- a/packages/cli/assets/templates/blocks/components/Slider/SliderShowcase.tsx+++ b/packages/cli/assets/templates/blocks/components/Slider/SliderShowcase.tsx@@ -12,7 +12,7 @@ export default function SliderShowcase() {label="Volume"value={value}onChange={setValue}- style={{width: 300}}+ containerStyle={{width: 300}}/>);}diff --git a/packages/cli/assets/templates/blocks/components/Slider/SliderWithMarks.tsx b/packages/cli/assets/templates/blocks/components/Slider/SliderWithMarks.tsxindex 97669120eb..303e80b72c 100644--- a/packages/cli/assets/templates/blocks/components/Slider/SliderWithMarks.tsx+++ b/packages/cli/assets/templates/blocks/components/Slider/SliderWithMarks.tsx@@ -9,7 +9,7 @@ export default function SliderWithMarks() {const [value, setValue] = useState(50);return (<Slider- style={{width: 300}}+ containerStyle={{width: 300}}label="Volume"value={value}onChange={setValue}diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsxindex fd471153b1..abd51e1948 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx@@ -37,7 +37,7 @@ export default function TokenizerClear() {value={value}onChange={items => setValue(items)}hasClear- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack>);diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsxindex 7cec358984..e3384e822a 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx@@ -44,7 +44,7 @@ export default function TokenizerCreatable() {onChange={items => setTags(items)}hasCreateplaceholder="Type a tag and press Enter..."- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack><Stack direction="vertical" gap={1}>@@ -59,7 +59,7 @@ export default function TokenizerCreatable() {hasCreatehasEntriesOnFocusplaceholder="Search or type a new name..."- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack></Stack>diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsxindex 04c8e1a7de..56b0510d9b 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx@@ -39,7 +39,7 @@ export default function TokenizerEndContent() {value={value}onChange={items => setValue(items)}endContent={<Button label="Apply" variant="primary" size="sm" />}- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack>);diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsxindex 60f8fd724f..d629859e39 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx@@ -38,7 +38,7 @@ export default function TokenizerIcon() {value={value}onChange={items => setValue(items)}startIcon={MagnifyingGlassIcon}- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack>);diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsxindex a6847e870b..d4c2459411 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx@@ -44,7 +44,7 @@ export default function TokenizerMaxEntries() {value={value}onChange={items => setValue(items)}maxEntries={MAX_SKILLS}- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack>);diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsxindex 17cf0beebf..891babc405 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx@@ -40,7 +40,7 @@ export default function TokenizerOverflow() {value={inlineValue}onChange={items => setInlineValue(items)}tokenOverflowBehavior="unfocusedInline"- style={{width: 400, maxWidth: 400}}+ containerStyle={{width: 400, maxWidth: 400}}/></Stack><Stack direction="vertical" gap={1}>@@ -54,7 +54,7 @@ export default function TokenizerOverflow() {value={layerValue}onChange={items => setLayerValue(items)}tokenOverflowBehavior="unfocusedLayer"- style={{width: 400, maxWidth: 400}}+ containerStyle={{width: 400, maxWidth: 400}}/></Stack></Stack>diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsxindex 9752e9bfaf..06ec2b775d 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx@@ -23,7 +23,7 @@ export default function TokenizerShowcase() {searchSource={source}value={value}onChange={setValue}- style={{width: 400}}+ containerStyle={{width: 400}}/>);}diff --git a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsxindex 1897592038..dc13ec0b4d 100644--- a/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx+++ b/packages/cli/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx@@ -39,7 +39,7 @@ export default function TokenizerStates() {value={[users[0], users[2]]}onChange={() => {}}isDisabled- style={{width: 400}}+ containerStyle={{width: 400}}/><Tokenizerlabel="Error message"@@ -49,7 +49,7 @@ export default function TokenizerStates() {onChange={items => setErrorValue(items)}isRequiredstatus={{type: 'error', message: 'At least one reviewer is required'}}- style={{width: 400}}+ containerStyle={{width: 400}}/><Tokenizerlabel="Warning message"@@ -61,7 +61,7 @@ export default function TokenizerStates() {type: 'warning',message: 'Consider adding at least 2 approvers',}}- style={{width: 400}}+ containerStyle={{width: 400}}/><Tokenizerlabel="Success message"@@ -70,7 +70,7 @@ export default function TokenizerStates() {value={successValue}onChange={items => setSuccessValue(items)}status={{type: 'success', message: 'All required reviewers added'}}- style={{width: 400}}+ containerStyle={{width: 400}}/></Stack>);diff --git a/packages/core/src/CheckboxList/CheckboxList.doc.mjs b/packages/core/src/CheckboxList/CheckboxList.doc.mjsindex c9bb9de85b..eb81ebfccc 100644--- a/packages/core/src/CheckboxList/CheckboxList.doc.mjs+++ b/packages/core/src/CheckboxList/CheckboxList.doc.mjs@@ -170,10 +170,36 @@ export const docs = {'Width of the field (number = pixels, string used as-is, e.g. "100%"). Sizes the whole field (label, control, and status) so they stay aligned.',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- 'StyleX styles for layout customization. Must be a stylex.create() value.',+ 'StyleX styles for the field container (label, control, and status together). No effect inside InputGroup (style the InputGroup instead) or in a `horizontal-labels` FormLayout. Root `xstyle`, `className`, and `style` are not accepted.',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: 'Class name for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ 'StyleX styles for the visual control box: the element that paints the border and background and holds icons and end controls. Never the native input.',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: 'Class name for the visual control box.',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the visual control box.',},],components: [{name: 'CheckboxListItem'}],diff --git a/packages/core/src/CheckboxList/CheckboxList.fr10.test.tsx b/packages/core/src/CheckboxList/CheckboxList.fr10.test.tsxnew file mode 100644index 0000000000..33a43681ca--- /dev/null+++ b/packages/core/src/CheckboxList/CheckboxList.fr10.test.tsx@@ -0,0 +1,24 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it} from 'vitest';+import {screen} from '@testing-library/react';+import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';+import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';+import {CheckboxList, type CheckboxListProps} from './CheckboxList';+import {CheckboxListItem} from './CheckboxListItem';++describe('CheckboxList props type (family:input-fields FR10)', () => {+ it('accepts container* and control* and no root styling', () => {+ expectFieldInputProps<CheckboxListProps>();+ });+});++describeFieldInputParts('CheckboxList', {+ renderMember: props => (+ <CheckboxList label="Preferences" value={[]} onChange={() => {}} {...props}>+ <CheckboxListItem label="A" value="a" />+ </CheckboxList>+ ),+ getControl: () => screen.getByRole('group'),+ inGroup: false,+});diff --git a/packages/core/src/CheckboxList/CheckboxList.test.tsx b/packages/core/src/CheckboxList/CheckboxList.test.tsxindex 1cca5eabe6..209a2676df 100644--- a/packages/core/src/CheckboxList/CheckboxList.test.tsx+++ b/packages/core/src/CheckboxList/CheckboxList.test.tsx@@ -469,15 +469,15 @@ describe('CheckboxList', () => {);});- it('forwards ref, className, and style to the field root and the item row', () => {+ it('forwards ref to the group, container* to the field root, and item styling to the row', () => {const listRef = createRef<HTMLDivElement>();const itemRef = createRef<HTMLLIElement>();- render(+ const {container} = render(<CheckboxListref={listRef}label="Preferences"- className="consumer-list"- style={{marginTop: 12}}+ containerClassName="consumer-list"+ containerStyle={{marginTop: 12}}value={[]}onChange={() => {}}><CheckboxListItem@@ -489,14 +489,13 @@ describe('CheckboxList', () => {/></CheckboxList>,);- expect(listRef.current).toContainElement(+ expect(listRef.current).toBe(screen.getByRole('group', {name: 'Preferences'}),);- expect(listRef.current).toHaveClass(- 'consumer-list',- 'astryx-checkbox-list',- );- expect(listRef.current).toHaveStyle({marginTop: '12px'});+ const fieldRoot = container.querySelector('.consumer-list');+ expect(fieldRoot).toHaveClass('astryx-checkbox-list');+ expect(fieldRoot).toHaveStyle({marginTop: '12px'});+ expect(fieldRoot).toContainElement(listRef.current);const row = screen.getByRole('listitem');expect(itemRef.current).toBe(row);expect(row).toHaveClass('consumer-item', 'astryx-list-item');diff --git a/packages/core/src/CheckboxList/CheckboxList.tsx b/packages/core/src/CheckboxList/CheckboxList.tsxindex f34ff119ca..cbd4c7d338 100644--- a/packages/core/src/CheckboxList/CheckboxList.tsx+++ b/packages/core/src/CheckboxList/CheckboxList.tsx@@ -24,13 +24,18 @@ import {useTransition,type ReactNode,} from 'react';-import type {BaseProps} from '../BaseProps';+import {+ type FieldInputBaseProps,+ useFieldInputStyling,+} from '../Field/fieldParts';+import {useMergedRefs} from '../hooks/useMergedRefs';import type {SizeValue} from '../utils/types';import {Field} from '../Field/Field';import type {InputStatus} from '../Field/types';import {List} from '../List/List';import type {ListDensity} from '../List/ListContext';import {useTooltip} from '../Tooltip';+import * as stylex from '@stylexjs/stylex';import {mergeProps} from '../utils';import {themeProps} from '../utils/themeProps';import {@@ -41,10 +46,10 @@ import {const EMPTY_ARRAY: string[] = [];export interface CheckboxListProps extends Omit<- BaseProps<HTMLDivElement>,+ FieldInputBaseProps<HTMLDivElement>,'onChange'> {- /** Ref forwarded to the root element */+ /** Ref forwarded to the `role="group"` element. */ref?: React.Ref<HTMLDivElement>;/*** Label text for the checkbox group (always rendered for accessibility).@@ -159,12 +164,20 @@ export function CheckboxList({children,ref,width,- xstyle,- className,- style,- 'data-testid': dataTestId,- ...rest+ containerXstyle,+ containerClassName,+ containerStyle,+ controlXstyle,+ controlClassName,+ controlStyle,+ 'aria-describedby': ariaDescribedByProp,+ ...restProps}: CheckboxListProps) {+ const {rest, container} = useFieldInputStyling('CheckboxList', restProps, {+ containerXstyle,+ containerClassName,+ containerStyle,+ });const inputID = useId();const labelID = useId();const descriptionID = useId();@@ -241,9 +254,6 @@ export function CheckboxList({return (<Field- {...rest}- ref={ref}- data-testid={dataTestId}label={label}isLabelHidden={isLabelHidden}description={description}@@ -263,20 +273,27 @@ export function CheckboxList({}statusVariant="detached"width={width}- xstyle={xstyle}- {...mergeProps(themeProps('checkbox-list'), {className, style})}>+ xstyle={container.xstyle}+ {...mergeProps(themeProps('checkbox-list'), {+ className: container.className,+ style: container.style,+ })}><CheckboxListContext value={contextValue}><div- ref={el => {- // Anchor + hover/focus listeners for the disabled-message tooltip.- // Handlers are gated internally by isEnabled, so attaching- // unconditionally is safe.- disabledMessageTooltip.ref(el);- }}+ {...rest}+ // The disabled-message tooltip anchors here; its handlers are gated+ // internally by isEnabled, so attaching unconditionally is safe.+ ref={useMergedRefs(ref, disabledMessageTooltip.ref)}+ {...mergeProps(+ stylex.props(controlXstyle),+ controlClassName,+ controlStyle,+ )}role="group"aria-labelledby={labelID}aria-describedby={[+ ariaDescribedByProp,description ? descriptionID : null,status?.message ? statusMessageID : null,showsDisabledMessage ? disabledMessageTooltip.describedBy : null,diff --git a/packages/core/src/Field/fieldInputFamily.render-testing.tsx b/packages/core/src/Field/fieldInputFamily.render-testing.tsxindex 4a3e6c1703..12b826a7a5 100644--- a/packages/core/src/Field/fieldInputFamily.render-testing.tsx+++ b/packages/core/src/Field/fieldInputFamily.render-testing.tsx@@ -27,6 +27,12 @@ export interface FieldInputPartsOptions {* set false only for a member whose control id is component-owned.*/forwardsId?: boolean;+ /**+ * Whether the primary semantic control itself references the field+ * description. Defaults to true; FileInput describes its trigger button+ * instead of the hidden native input that takes base props.+ */+ controlReferencesDescription?: boolean;}/**@@ -41,6 +47,7 @@ export function describeFieldInputParts(getControl,inGroup = false,forwardsId = true,+ controlReferencesDescription = true,}: FieldInputPartsOptions,): void {describe(`${name} FR10 prop targets`, () => {@@ -73,6 +80,27 @@ export function describeFieldInputParts(expect(onFocus).toHaveBeenCalled();});+ it('keeps a caller aria-describedby alongside the field description', () => {+ render(+ renderMember({+ 'aria-describedby': 'caller-help',+ // eslint-disable-next-line @astryx/no-hardcoded-i18n-string -- test fixture text+ description: 'Field help',+ }),+ );+ const ids = (getControl().getAttribute('aria-describedby') ?? '').split(+ ' ',+ );+ expect(ids).toContain('caller-help');+ if (!controlReferencesDescription) {+ return;+ }+ const describedText = ids+ .map(id => document.getElementById(id)?.textContent ?? '')+ .join(' ');+ expect(describedText).toContain('Field help');+ });+it('styles the Field box with container* and the control box with control*', () => {const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});const {container} = render(diff --git a/packages/core/src/Field/fieldInputFamily.test.tsx b/packages/core/src/Field/fieldInputFamily.test.tsxindex f001a15daf..a74c02b0cb 100644--- a/packages/core/src/Field/fieldInputFamily.test.tsx+++ b/packages/core/src/Field/fieldInputFamily.test.tsx@@ -29,11 +29,6 @@ const PENDING_FR10 = new Set(['MultiSelector','ComplexSelector',// field-root batch- 'Typeahead',- 'Tokenizer',- 'CheckboxList',- 'RadioList',- 'Slider',]);function fieldComposedComponents(): string[] {diff --git a/packages/core/src/FileInput/FileInput.fr10.test.tsx b/packages/core/src/FileInput/FileInput.fr10.test.tsxindex a6e7b87f45..67b3af0f6c 100644--- a/packages/core/src/FileInput/FileInput.fr10.test.tsx+++ b/packages/core/src/FileInput/FileInput.fr10.test.tsx@@ -17,4 +17,5 @@ describeFieldInputParts('FileInput', {),getControl: () => document.querySelector<HTMLElement>('input[type="file"]')!,inGroup: false,+ controlReferencesDescription: false,});diff --git a/packages/core/src/Markdown/Markdown.tsx b/packages/core/src/Markdown/Markdown.tsxindex 68888d209d..5d64d54532 100644--- a/packages/core/src/Markdown/Markdown.tsx+++ b/packages/core/src/Markdown/Markdown.tsx@@ -1662,7 +1662,7 @@ function renderBlock(label={t('@astryx.markdown.taskList')}isLabelHiddenvalue={checkedValues}- xstyle={styles.blockIndent}+ containerXstyle={styles.blockIndent}isReadOnlydensity="compact">{node.children.map((item, i) => {diff --git a/packages/core/src/NumberInput/NumberInput.tsx b/packages/core/src/NumberInput/NumberInput.tsxindex ebb1f13deb..bbcc6ea307 100644--- a/packages/core/src/NumberInput/NumberInput.tsx+++ b/packages/core/src/NumberInput/NumberInput.tsx@@ -573,6 +573,7 @@ export function NumberInput({controlStyle,ref,id: idProp,+ 'aria-describedby': ariaDescribedByProp,...restProps}: NumberInputProps) {const {rest, container} = useFieldInputStyling('NumberInput', restProps, {@@ -943,7 +944,10 @@ export function NumberInput({aria-valuetext={value == null || !formatValue ? undefined : formattedValue}- aria-describedby={ariaDescribedBy}+ aria-describedby={+ [ariaDescribedByProp, ariaDescribedBy].filter(Boolean).join(' ') ||+ undefined+ }aria-required={isEffectivelyRequired ? 'true' : undefined}aria-invalid={status?.type === 'error' || !isInputValid ? 'true' : undefineddiff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsxindex ae7bfb3b97..43ef97a01d 100644--- a/packages/core/src/PowerSearch/PowerSearch.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.tsx@@ -1087,9 +1087,9 @@ export function PowerSearch({statusVariant={statusVariant}onFocus={onFocus}onBlur={onBlur}- xstyle={xstyle}- className={className}- style={style}+ containerXstyle={xstyle}+ containerClassName={className}+ containerStyle={style}data-testid={testId}/></div>diff --git a/packages/core/src/RadioList/RadioList.doc.mjs b/packages/core/src/RadioList/RadioList.doc.mjsindex dc5cb57e1a..adce608039 100644--- a/packages/core/src/RadioList/RadioList.doc.mjs+++ b/packages/core/src/RadioList/RadioList.doc.mjs@@ -140,10 +140,36 @@ export const docs = {'Width of the field (number = pixels, string used as-is, e.g. "100%"). Sizes the whole field (label, control, and status) so they stay aligned.',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value: not an inline style object like style={{}}.',+ 'StyleX styles for the field container (label, control, and status together). No effect inside InputGroup (style the InputGroup instead) or in a `horizontal-labels` FormLayout. Root `xstyle`, `className`, and `style` are not accepted.',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: 'Class name for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ 'StyleX styles for the visual control box: the element that paints the border and background and holds icons and end controls. Never the native input.',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: 'Class name for the visual control box.',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the visual control box.',},],components: [{name: 'RadioListItem'}],diff --git a/packages/core/src/RadioList/RadioList.fr10.test.tsx b/packages/core/src/RadioList/RadioList.fr10.test.tsxnew file mode 100644index 0000000000..743a9cf7a6--- /dev/null+++ b/packages/core/src/RadioList/RadioList.fr10.test.tsx@@ -0,0 +1,24 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it} from 'vitest';+import {screen} from '@testing-library/react';+import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';+import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';+import {RadioList, type RadioListProps} from './RadioList';+import {RadioListItem} from './RadioListItem';++describe('RadioList props type (family:input-fields FR10)', () => {+ it('accepts container* and control* and no root styling', () => {+ expectFieldInputProps<RadioListProps>();+ });+});++describeFieldInputParts('RadioList', {+ renderMember: props => (+ <RadioList label="Plan" value="a" onChange={() => {}} {...props}>+ <RadioListItem label="A" value="a" />+ </RadioList>+ ),+ getControl: () => screen.getByRole('radiogroup'),+ inGroup: false,+});diff --git a/packages/core/src/RadioList/RadioList.tsx b/packages/core/src/RadioList/RadioList.tsxindex da36b36836..b838fb9611 100644--- a/packages/core/src/RadioList/RadioList.tsx+++ b/packages/core/src/RadioList/RadioList.tsx@@ -30,8 +30,11 @@ import {Field} from '../Field/Field';import type {InputStatus} from '../Field/types';import {useTooltip} from '../Tooltip';import {useResolvedRequired} from '../hooks/useResolvedRequired';-import {mergeProps} from '../utils';-import type {BaseProps} from '../BaseProps';+import {composeEventHandlers, mergeProps} from '../utils';+import {+ type FieldInputBaseProps,+ useFieldInputStyling,+} from '../Field/fieldParts';import type {SizeValue} from '../utils/types';import {themeProps} from '../utils/themeProps';@@ -77,9 +80,10 @@ const styles = stylex.create({});export interface RadioListProps extends Omit<- BaseProps<HTMLElement>,+ FieldInputBaseProps<HTMLDivElement>,'onChange'> {+ /** Ref forwarded to the `role="radiogroup"` element. */ref?: React.Ref<HTMLDivElement>;/*** Label text for the radio group (always rendered for accessibility).@@ -203,13 +207,23 @@ export function RadioList({status,labelTooltip,width,- xstyle,- className,- style,- 'data-testid': dataTestId,+ containerXstyle,+ containerClassName,+ containerStyle,+ controlXstyle,+ controlClassName,+ controlStyle,htmlName,children,+ onFocus,+ 'aria-describedby': ariaDescribedByProp,+ ...restProps}: RadioListProps) {+ const {rest, container} = useFieldInputStyling('RadioList', restProps, {+ containerXstyle,+ containerClassName,+ containerStyle,+ });const autoName = useId();const name = htmlName ?? autoName;const inputID = useId();@@ -347,8 +361,7 @@ export function RadioList({return (<Field- ref={ref}- data-testid={dataTestId}+ {...container}label={label}isLabelHidden={isLabelHidden}description={description}@@ -370,13 +383,16 @@ export function RadioList({}labelTooltip={labelTooltip}statusVariant="detached"- width={width}- xstyle={xstyle}- className={className}- style={style}>+ width={width}><div+ {...rest}ref={el => {groupRef.current = el;+ if (typeof ref === 'function') {+ ref(el);+ } else if (ref) {+ ref.current = el;+ }// Anchor + hover/focus listeners for the disabled-message tooltip.// Handlers are gated internally by isEnabled, so attaching// unconditionally is safe.@@ -384,9 +400,10 @@ export function RadioList({}}role="radiogroup"aria-labelledby={labelID}- onFocus={handleFocus}+ onFocus={composeEventHandlers(handleFocus, onFocus)}aria-describedby={[+ ariaDescribedByProp,description ? descriptionID : null,status?.message ? statusMessageID : null,showsDisabledMessage ? disabledMessageTooltip.describedBy : null,@@ -401,7 +418,10 @@ export function RadioList({stylex.props(styles.radiogroup,orientation === 'vertical' ? styles.vertical : styles.horizontal,+ controlXstyle,),+ controlClassName,+ controlStyle,)}><RadioListContext value={contextValue}>{children}</RadioListContext></div>diff --git a/packages/core/src/Slider/Slider.doc.mjs b/packages/core/src/Slider/Slider.doc.mjsindex 563a69774b..13c251385c 100644--- a/packages/core/src/Slider/Slider.doc.mjs+++ b/packages/core/src/Slider/Slider.doc.mjs@@ -229,10 +229,36 @@ export const docs = {'Width of the field (number = pixels, string used as-is, e.g. "100%"). Sizes the whole field (label, control, and status) so they stay aligned.',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.',+ 'StyleX styles for the field container (label, control, and status together). No effect inside InputGroup (style the InputGroup instead) or in a `horizontal-labels` FormLayout. Root `xstyle`, `className`, and `style` are not accepted.',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: 'Class name for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ 'StyleX styles for the visual control box: the element that paints the border and background and holds icons and end controls. Never the native input.',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: 'Class name for the visual control box.',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the visual control box.',},],theming: {@@ -427,10 +453,36 @@ export const docsZh = {description: '标签旁信息图标的提示文本。',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- '用于布局自定义的 StyleX 样式(边距、定位、尺寸)。必须是 stylex.create() 的值,而非内联样式对象如 style={{}}。',+ '字段容器(标签、控件和状态整体)的 StyleX 样式。在 InputGroup 内(请改为设置 InputGroup 的样式)或 `horizontal-labels` FormLayout 中无效。不接受根级 `xstyle`、`className` 和 `style`。',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: '字段容器的类名,作用目标同 `containerXstyle`。',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: '字段容器的内联样式,作用目标同 `containerXstyle`。',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ '可视控件框的 StyleX 样式:绘制边框和背景并包含图标与尾部控件的元素,而非原生输入元素。',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: '可视控件框的类名。',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: '可视控件框的内联样式。',},],theming: {@@ -522,6 +574,12 @@ export const docsDense = {],},propDescriptions: {+ containerXstyle: 'StyleX styles for the field container; no effect in InputGroup or horizontal-labels FormLayout. No root xstyle/className/style.',+ containerClassName: 'Class name for the field container.',+ containerStyle: 'Inline styles for the field container.',+ controlXstyle: 'StyleX styles for the visual control box (border, background, icons); not the native input.',+ controlClassName: 'Class name for the visual control box.',+ controlStyle: 'Inline styles for the visual control box.',label: 'Label text (always rendered for a11y).',value:'Current value; number for single thumb, [number, number] for range.',@@ -546,6 +604,5 @@ export const docsDense = {description: 'Description text below label.',status: 'Status indicator ({type, message}) for validation feedback.',labelTooltip: 'Tooltip text for info icon next to label.',- xstyle: 'StyleX layout styles; must be stylex.create() value.',},};diff --git a/packages/core/src/Slider/Slider.fr10.test.tsx b/packages/core/src/Slider/Slider.fr10.test.tsxnew file mode 100644index 0000000000..da9d413b08--- /dev/null+++ b/packages/core/src/Slider/Slider.fr10.test.tsx@@ -0,0 +1,59 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it, expect, vi} from 'vitest';+import {fireEvent, render, screen} from '@testing-library/react';+import {createRef} from 'react';+import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';+import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';+import {Slider, type SliderProps} from './Slider';++describe('Slider props type (family:input-fields FR10)', () => {+ it('accepts container* and control* and no root styling', () => {+ expectFieldInputProps<SliderProps>();+ });+});++describeFieldInputParts('Slider', {+ renderMember: props => (+ <Slider label="Volume" value={50} onChange={() => {}} {...props} />+ ),+ getControl: () => screen.getByRole('slider'),+ inGroup: false,+});++describe('Slider range mode prop targets', () => {+ it('forwards base props and ref to the role="group" control', () => {+ const ref = createRef<HTMLDivElement>();+ render(+ <Slider+ label="Price"+ value={[20, 80]}+ onChange={() => {}}+ ref={ref}+ data-testid="price"+ aria-details="price-help"+ />,+ );+ const group = screen.getByRole('group', {name: 'Price'});+ expect(ref.current).toBe(group);+ expect(group).toHaveAttribute('data-testid', 'price');+ expect(group).toHaveAttribute('aria-details', 'price-help');+ });++ it('calls a consumer onPointerDown after its own press handling', () => {+ const onPointerDown = vi.fn();+ render(+ <Slider+ label="Volume"+ value={50}+ onChange={() => {}}+ onPointerDown={onPointerDown}+ />,+ );+ const control = document.querySelector<HTMLElement>(+ '.astryx-slider-control',+ )!;+ fireEvent.pointerDown(control, {pointerId: 1, clientX: 10, clientY: 5});+ expect(onPointerDown).toHaveBeenCalledOnce();+ });+});diff --git a/packages/core/src/Slider/Slider.tsx b/packages/core/src/Slider/Slider.tsxindex 16812b521f..0373c33efa 100644--- a/packages/core/src/Slider/Slider.tsx+++ b/packages/core/src/Slider/Slider.tsx@@ -48,7 +48,10 @@ import {useInteractionModalityTracking,} from '../utils/interactionModality';import {isRtlElement} from '../hooks/isRtlElement';-import type {BaseProps} from '../BaseProps';+import {+ type FieldInputBaseProps,+ useFieldInputStyling,+} from '../Field/fieldParts';import type {SizeValue} from '../utils/types';import {themeProps} from '../utils/themeProps';@@ -58,10 +61,10 @@ import {useMergedRefs} from '../hooks/useMergedRefs';// =============================================================================export interface SliderBaseProps extends Omit<- BaseProps<HTMLDivElement>,+ FieldInputBaseProps<HTMLDivElement>,'onChange'> {- /** Ref forwarded to the root element */+ /** Ref forwarded to the slider control element. */ref?: React.Ref<HTMLDivElement>;/** Label text for the slider (always rendered for accessibility). */label: string;@@ -486,14 +489,33 @@ export function Slider({ref, ...props}: SliderProps) {valueDisplay = 'tooltip',marks,width,- xstyle,- className,- style,- 'data-testid': testId,+ containerXstyle,+ containerClassName,+ containerStyle,+ controlXstyle,+ controlClassName,+ controlStyle,value,onChange,onChangeEnd,+ onPointerDown,+ onPointerMove,+ onPointerUp,+ onPointerCancel,+ onKeyDown,+ onFocus,+ onBlur,+ id: idProp,+ 'aria-describedby': ariaDescribedByProp,+ ...restWithRange} = props;+ const {minStepsBetweenThumbs: _minSteps, ...restProps} =+ restWithRange as typeof restWithRange & {minStepsBetweenThumbs?: number};+ const {rest, container} = useFieldInputStyling('Slider', restProps, {+ containerXstyle,+ containerClassName,+ containerStyle,+ });const isRange = Array.isArray(value);const minStepsBetweenThumbs =@@ -503,7 +525,17 @@ export function Slider({ref, ...props}: SliderProps) {const isHorizontal = orientation === 'horizontal';- const id = useId();+ // Consumer handlers run after the component's own and always run: the+ // component's handlers call preventDefault() for their own reasons, which+ // must not silence a consumer.+ const after =+ <E,>(own: (event: E) => void, consumer?: (event: E) => void) =>+ (event: E) => {+ own(event);+ consumer?.(event);+ };+ const generatedId = useId();+ const id = idProp ?? generatedId;const labelID = useId();const descriptionID = useId();const statusMessageID = useId();@@ -901,6 +933,8 @@ export function Slider({ref, ...props}: SliderProps) {const thumbElement = (<divkey={thumbIndex}+ {...(!isRange ? rest : undefined)}+ ref={!isRange ? ref : undefined}id={!isRange ? id : undefined}role="slider"// With a disabledMessage the thumb keeps focusability so the reason is@@ -916,10 +950,20 @@ export function Slider({ref, ...props}: SliderProps) {aria-invalid={status?.type === 'error' ? true : undefined}aria-label={thumbLabel}aria-labelledby={!isRange ? labelID : undefined}- aria-describedby={ariaDescribedBy}- onKeyDown={e => handleKeyDown(thumbIndex, e)}- onFocus={e => handleThumbFocus(thumbIndex, e)}- onBlur={handleThumbBlur}+ aria-describedby={+ [!isRange ? ariaDescribedByProp : undefined, ariaDescribedBy]+ .filter(Boolean)+ .join(' ') || undefined+ }+ onKeyDown={after(+ e => handleKeyDown(thumbIndex, e),+ !isRange ? onKeyDown : undefined,+ )}+ onFocus={after(+ e => handleThumbFocus(thumbIndex, e),+ !isRange ? onFocus : undefined,+ )}+ onBlur={after(handleThumbBlur, !isRange ? onBlur : undefined)}{...mergeProps(themeProps('slider-thumb', {orientation,@@ -991,7 +1035,7 @@ export function Slider({ref, ...props}: SliderProps) {return (<Field- data-testid={testId}+ {...container}label={label}isLabelHidden={isLabelHidden}description={description}@@ -1019,10 +1063,7 @@ export function Slider({ref, ...props}: SliderProps) {}labelTooltip={labelTooltip}statusVariant="detached"- width={width}- xstyle={xstyle}- className={className}- style={style}>+ width={width}><div{...mergeProps(themeProps('slider', {@@ -1045,14 +1086,29 @@ export function Slider({ref, ...props}: SliderProps) {/>))}<div- ref={useMergedRefs(ref, trackRef, disabledMessageTooltip.ref)}+ // In range mode the role="group" control takes the base props; a+ // single slider gives them to its role="slider" thumb.+ {...(isRange ? rest : undefined)}+ {...(isRange+ ? {+ onKeyDown,+ onFocus,+ onBlur,+ 'aria-describedby': ariaDescribedByProp,+ }+ : undefined)}+ ref={useMergedRefs(+ isRange ? ref : undefined,+ trackRef,+ disabledMessageTooltip.ref,+ )}{...(isRange? {role: 'group', 'aria-labelledby': labelID}: undefined)}- onPointerDown={handlePointerDown}- onPointerMove={handlePointerMove}- onPointerUp={handlePointerUp}- onPointerCancel={handlePointerUp}+ onPointerDown={after(handlePointerDown, onPointerDown)}+ onPointerMove={after(handlePointerMove, onPointerMove)}+ onPointerUp={after(handlePointerUp, onPointerUp)}+ onPointerCancel={after(handlePointerUp, onPointerCancel)}{...mergeProps(themeProps('slider-control', {orientation,@@ -1064,7 +1120,10 @@ export function Slider({ref, ...props}: SliderProps) {? styles.trackContainerHorizontal: styles.trackContainerVertical,isDisabled && styles.trackContainerDisabled,+ controlXstyle,),+ controlClassName,+ controlStyle,)}>{/* Background track */}<divdiff --git a/packages/core/src/TextArea/TextArea.doc.mjs b/packages/core/src/TextArea/TextArea.doc.mjsindex b0f75ad90e..4620094fda 100644--- a/packages/core/src/TextArea/TextArea.doc.mjs+++ b/packages/core/src/TextArea/TextArea.doc.mjs@@ -261,12 +261,6 @@ export const docs = {description:'The native autocomplete attribute, forwarded to the textarea unchanged. Does not affect the controlled value.',},- {- name: 'xstyle',- type: 'StyleXStyles',- description:- 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.',- },{name: 'containerXstyle',type: 'StyleXStyles',@@ -541,12 +535,6 @@ export const docsZh = {type: 'string',description: '原生 autocomplete 属性,原样转发给文本域。不影响受控的值。',},- {- name: 'xstyle',- type: 'StyleXStyles',- description:- 'StyleX 样式,用于布局自定义(边距、定位、尺寸)。必须是 stylex.create() 的值,而非内联样式对象。',- },{name: 'containerXstyle',type: 'StyleXStyles',@@ -745,7 +733,5 @@ export const docsDense = {onBlur: 'Callback on blur.',autoComplete:'Native autocomplete attr, forwarded unchanged. Does not affect the controlled value.',- xstyle:- 'StyleX styles for layout customization. Must be stylex.create() value, not inline style.',},};diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsxindex a86774822a..acd78d23f3 100644--- a/packages/core/src/TextArea/TextArea.tsx+++ b/packages/core/src/TextArea/TextArea.tsx@@ -412,6 +412,7 @@ export function TextArea({controlStyle,ref,id: idProp,+ 'aria-describedby': ariaDescribedByProp,...restProps}: TextAreaProps) {const {rest, container} = useFieldInputStyling('TextArea', restProps, {@@ -627,7 +628,10 @@ export function TextArea({spellCheck={hasSpellCheck}autoFocus={hasAutoFocus}data-autofocus={hasAutoFocus || undefined}- aria-describedby={ariaDescribedBy}+ aria-describedby={+ [ariaDescribedByProp, ariaDescribedBy].filter(Boolean).join(' ') ||+ undefined+ }aria-required={isEffectivelyRequired ? 'true' : undefined}aria-invalid={status?.type === 'error' ||diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsxindex 2e3c220bff..b35e354cb9 100644--- a/packages/core/src/TextInput/TextInput.tsx+++ b/packages/core/src/TextInput/TextInput.tsx@@ -320,6 +320,7 @@ export function TextInput({controlStyle,ref,id: idProp,+ 'aria-describedby': ariaDescribedByProp,...restProps}: TextInputProps) {const {rest, container} = useFieldInputStyling('TextInput', restProps, {@@ -489,7 +490,10 @@ export function TextInput({readOnly={isReadOnly || showsDisabledMessage || undefined}autoFocus={hasAutoFocus}data-autofocus={hasAutoFocus || undefined}- aria-describedby={ariaDescribedBy}+ aria-describedby={+ [ariaDescribedByProp, ariaDescribedBy].filter(Boolean).join(' ') ||+ undefined+ }aria-required={isEffectivelyRequired ? 'true' : undefined}aria-invalid={status?.type === 'error' ? 'true' : undefined}aria-busy={isBusy || undefined}diff --git a/packages/core/src/Tokenizer/Tokenizer.doc.mjs b/packages/core/src/Tokenizer/Tokenizer.doc.mjsindex 9199cf1673..d9293f3404 100644--- a/packages/core/src/Tokenizer/Tokenizer.doc.mjs+++ b/packages/core/src/Tokenizer/Tokenizer.doc.mjs@@ -265,10 +265,36 @@ export const docs = {description: 'Fires when focus leaves the tokenizer input.',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value; not an inline style object like style={{}}.',+ 'StyleX styles for the field container (label, control, and status together). No effect inside InputGroup (style the InputGroup instead) or in a `horizontal-labels` FormLayout. Root `xstyle`, `className`, and `style` are not accepted.',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: 'Class name for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ 'StyleX styles for the visual control box: the element that paints the border and background and holds icons and end controls. Never the native input.',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: 'Class name for the visual control box.',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the visual control box.',},],theming: {@@ -585,10 +611,36 @@ export const docsZh = {description: '用于 focus() 和 blur() 控制的命令式句柄。',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- '\u7528\u4e8e\u5e03\u5c40\u81ea\u5b9a\u4e49\u7684 StyleX \u6837\u5f0f\uff08\u5916\u8fb9\u8ddd\u3001\u5b9a\u4f4d\u3001\u5c3a\u5bf8\uff09\u3002\u5fc5\u987b\u662f stylex.create() \u7684\u503c; \u4e0d\u80fd\u662f\u5185\u8054\u6837\u5f0f\u5bf9\u8c61\u5982 style={{}}\u3002',+ '字段容器(标签、控件和状态整体)的 StyleX 样式。在 InputGroup 内(请改为设置 InputGroup 的样式)或 `horizontal-labels` FormLayout 中无效。不接受根级 `xstyle`、`className` 和 `style`。',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: '字段容器的类名,作用目标同 `containerXstyle`。',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: '字段容器的内联样式,作用目标同 `containerXstyle`。',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ '可视控件框的 StyleX 样式:绘制边框和背景并包含图标与尾部控件的元素,而非原生输入元素。',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: '可视控件框的类名。',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: '可视控件框的内联样式。',},],theming: {@@ -742,6 +794,12 @@ export const docsDense = {],},propDescriptions: {+ containerXstyle: 'StyleX styles for the field container; no effect in InputGroup or horizontal-labels FormLayout. No root xstyle/className/style.',+ containerClassName: 'Class name for the field container.',+ containerStyle: 'Inline styles for the field container.',+ controlXstyle: 'StyleX styles for the visual control box (border, background, icons); not the native input.',+ controlClassName: 'Class name for the visual control box.',+ controlStyle: 'Inline styles for the visual control box.',label: 'Accessible label for input.',searchSource:'Data source w/ search+bootstrap methods for populating dropdown.',@@ -783,7 +841,5 @@ export const docsDense = {'Icon at input start, before tokens. Icon name, SVG component, or ReactNode.',endContent: 'Content at input row end. For buttons, counts, controls.',handleRef: 'Imperative handle for focus() and blur() control.',- xstyle:- 'StyleX layout styles (margins, positioning). Must be stylex.create() value.',},};diff --git a/packages/core/src/Tokenizer/Tokenizer.fr10.test.tsx b/packages/core/src/Tokenizer/Tokenizer.fr10.test.tsxnew file mode 100644index 0000000000..34bac37ad8--- /dev/null+++ b/packages/core/src/Tokenizer/Tokenizer.fr10.test.tsx@@ -0,0 +1,28 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it} from 'vitest';+import {screen} from '@testing-library/react';+import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';+import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';+import type {SearchableItem} from '../Typeahead/types';+import {Tokenizer, type TokenizerProps} from './Tokenizer';++describe('Tokenizer props type (family:input-fields FR10)', () => {+ it('accepts container* and control* and no root styling', () => {+ expectFieldInputProps<TokenizerProps<SearchableItem>>();+ });+});++describeFieldInputParts('Tokenizer', {+ renderMember: props => (+ <Tokenizer+ label="Members"+ searchSource={{search: () => [], bootstrap: () => []}}+ value={[]}+ onChange={() => {}}+ {...props}+ />+ ),+ getControl: () => screen.getByRole('combobox'),+ inGroup: false,+});diff --git a/packages/core/src/Tokenizer/Tokenizer.test.tsx b/packages/core/src/Tokenizer/Tokenizer.test.tsxindex 7f262d07d0..939f00d5ff 100644--- a/packages/core/src/Tokenizer/Tokenizer.test.tsx+++ b/packages/core/src/Tokenizer/Tokenizer.test.tsx@@ -154,20 +154,19 @@ describe('Tokenizer minQueryLength', () => {});describe('Tokenizer', () => {- it('forwards DOM props and ref while preserving focus callbacks', () => {- const ref = createRef<HTMLDivElement>();+ it('forwards DOM props and ref to the combobox input while preserving focus callbacks', () => {+ const ref = createRef<HTMLInputElement>();const onClick = vi.fn();const onFocus = vi.fn();const onBlur = vi.fn();- render(+ const {container} = render(<Tokenizerref={ref}id="members-field"data-tracking="members-picker"- data-testid="members-surface"- aria-label="Picker region"- className="custom-tokenizer"- style={{marginTop: 7}}+ data-testid="members-input"+ containerClassName="custom-tokenizer"+ containerStyle={{marginTop: 7}}label="Members"searchSource={userSource}value={[users[0]]}@@ -177,15 +176,19 @@ describe('Tokenizer', () => {onBlur={onBlur}/>,);- const surface = screen.getByTestId('members-surface');const input = screen.getByRole('combobox');+ const surface = container.querySelector('.astryx-tokenizer');- expect(ref.current).toBeInstanceOf(HTMLDivElement);- expect(ref.current).toHaveClass('astryx-field');- expect(surface).toHaveClass('astryx-tokenizer');+ expect(ref.current).toBe(input);+ expect(input).toHaveAttribute('id', 'members-field');+ expect(input).toHaveAttribute('data-tracking', 'members-picker');+ expect(screen.getByTestId('members-input')).toBe(input);expect(surface).toHaveAttribute('aria-label', 'Members');+ const fieldRoot = container.querySelector('.custom-tokenizer');+ expect(fieldRoot).toHaveClass('astryx-field');+ expect(fieldRoot).toHaveStyle({marginTop: '7px'});- fireEvent.click(surface);+ fireEvent.click(input);expect(onClick).toHaveBeenCalledOnce();expect(onFocus).toHaveBeenCalledOnce();@@ -481,10 +484,9 @@ describe('Tokenizer', () => {searchSource={userSource}value={[users[0], users[1]]}onChange={() => {}}- data-testid="tokenizer"/>,);- const wrapper = screen.getByTestId('tokenizer');+ const wrapper = _container.querySelector('.astryx-tokenizer')!;// Tokens should be direct children of the wrapper, not nested in a divconst tokenElements = wrapper.querySelectorAll(':scope > span');expect(tokenElements.length).toBeGreaterThanOrEqual(2);@@ -1942,3 +1944,30 @@ describe('Tokenizer emptySearchText', () => {warn.mockRestore();});});++describe('Tokenizer consumer key handler order', () => {+ it('runs onKeyDown on the input after built-in key handling, so it cannot cancel token removal', () => {+ let currentTarget: EventTarget | null = null;+ const onKeyDown = vi.fn((event: React.KeyboardEvent) => {+ currentTarget = event.currentTarget;+ event.preventDefault();+ });+ const onChange = vi.fn();+ const {container} = render(+ <Tokenizer+ label="Members"+ searchSource={userSource}+ value={[users[0], users[1]]}+ onChange={onChange}+ onKeyDown={onKeyDown}+ />,+ );+ fireEvent.keyDown(screen.getByRole('combobox'), {key: 'Backspace'});+ expect(onChange).toHaveBeenCalledWith([users[0]], {+ item: users[1],+ type: 'remove',+ });+ expect(onKeyDown).toHaveBeenCalledOnce();+ expect(currentTarget).toBe(screen.getByRole('combobox'));+ });+});diff --git a/packages/core/src/Tokenizer/Tokenizer.tsx b/packages/core/src/Tokenizer/Tokenizer.tsxindex e469dae359..ede69ed009 100644--- a/packages/core/src/Tokenizer/Tokenizer.tsx+++ b/packages/core/src/Tokenizer/Tokenizer.tsx@@ -31,7 +31,12 @@ import {useIsBusy,type BusyIndicatorLane,} from '../Typeahead/busyIndicatorLane';-import type {BaseProps} from '../BaseProps';+import {TrailingKeyDownContext} from '../Typeahead/trailingKeyDown';+import {+ type FieldInputBaseProps,+ useFieldInputStyling,+} from '../Field/fieldParts';+import {useMergedRefs} from '../hooks/useMergedRefs';import type {SizeValue} from '../utils/types';import {BaseTypeahead} from '../Typeahead/BaseTypeahead';import {useSize} from '../SizeContext/SizeContext';@@ -106,9 +111,16 @@ export interface TokenizerHandle {}export interface TokenizerProps<T extends SearchableItem> extends Omit<- BaseProps<HTMLDivElement>,- 'onChange'+ FieldInputBaseProps<HTMLInputElement>,+ 'onChange' | 'onFocus' | 'onBlur' | 'onKeyDown'> {+ /**+ * Key handler. Runs after the built-in key handling, so it observes every key+ * and cannot cancel navigation, selection, or token editing. It receives keys+ * on the combobox input and on the field's other controls (the clear button+ * and tokens).+ */+ onKeyDown?: React.KeyboardEventHandler<HTMLElement>;/** Accessible label (required). */label: string;/** Visually hide the label. @default false */@@ -257,8 +269,8 @@ export interface TokenizerProps<T extends SearchableItem> extends Omit<onFocus?: (e: React.FocusEvent) => void;/** Fires when focus leaves the tokenizer entirely. */onBlur?: (e: React.FocusEvent) => void;- /** Ref forwarded to the root field element. */- ref?: React.Ref<HTMLDivElement>;+ /** Ref forwarded to the combobox input. */+ ref?: React.Ref<HTMLInputElement>;/** Imperative handle ref for focus/blur control. */handleRef?: React.Ref<TokenizerHandle>;}@@ -581,17 +593,28 @@ export function Tokenizer<T extends SearchableItem>({onFocus,onBlur,width,- xstyle,- className,- style,- 'data-testid': testId,+ containerXstyle,+ containerClassName,+ containerStyle,+ controlXstyle,+ controlClassName,+ controlStyle,ref,handleRef,- ...rest+ onKeyDown,+ id: idProp,+ 'aria-describedby': ariaDescribedByProp,+ ...restProps}: TokenizerProps<T>) {+ const {rest, container} = useFieldInputStyling('Tokenizer', restProps, {+ containerXstyle,+ containerClassName,+ containerStyle,+ });const t = useTranslator();const size = useSize(sizeProp, 'md');- const inputId = useId();+ const generatedInputId = useId();+ const inputId = idProp ?? generatedInputId;const descriptionId = useId();const statusMessageId = useId();const inputRef = useRef<HTMLInputElement>(null);@@ -943,7 +966,14 @@ export function Tokenizer<T extends SearchableItem>({onClick={handleWrapperClick}onFocusCapture={handleFocusCapture}onBlurCapture={handleBlurCapture}- data-testid={testId}+ // Keys on the field's other controls (clear button, tokens) reach a+ // consumer onKeyDown here; keys on the input reach it through+ // TrailingKeyDownContext after the built-in handling.+ onKeyDown={event => {+ if (event.target !== inputRef.current) {+ onKeyDown?.(event);+ }+ }}{...mergeProps(themeProps('tokenizer', {size,@@ -960,7 +990,10 @@ export function Tokenizer<T extends SearchableItem>({status && inputStatusBorderStyles[status.type],status && !isDisabled && inputStatusHoverShadowStyles[status.type],status && inputStatusFocusWithinStyles[status.type],+ controlXstyle,),+ controlClassName,+ controlStyle,)}>{startIcon && (<span {...stylex.props(value.length > 0 && styles.startIconWithTokens)}>@@ -985,43 +1018,50 @@ export function Tokenizer<T extends SearchableItem>({indicator lands in the end controls below beside the clearbutton rather than as a second one inside the base. */}<BusyIndicatorLaneProvider value={busyLane}>- <BaseTypeahead- ref={inputRef}- searchSource={isAtMax ? emptySource : filteredSource}- value={null}- onChange={handleAdd}- renderItem={renderItem}- // A space keeps :placeholder-shown available as the CSS-only empty- // query signal without painting placeholder text beside tokens.- placeholder={value.length === 0 ? placeholder : ' '}- hasEntriesOnFocus={isAtMax ? false : hasEntriesOnFocus}- maxMenuItems={maxMenuItems}- menuWidth={menuWidth}- minQueryLength={minQueryLength}- emptySearchText={emptySearchText}- isDisabled={isDisabled}- isFocusableDisabled={showsDisabledMessage}- hasAutoFocus={hasAutoFocus}- inputId={inputId}- ariaDescribedBy={ariaDescribedBy}- onChangeQuery={onChangeQuery}- __queryEntries={createEntries}- debounceMs={debounceMs}- onKeyDown={handleKeyDown}- anchorRef={wrapperRef}- size={size}- inputXStyle={[- isAtMax || isTruncated- ? styles.inputAtMax- : value.length > 0- ? [styles.inputCompact, compactInputSizeStyles[size]]- : undefined,- // The compact-token style owns the same reserve with an empty-query- // exception. This standalone rule is only for an empty Tokenizer;- // it still resolves to zero until the lane publishes a width.- !(isAtMax || isTruncated || value.length > 0) && laneReserve,- ]}- />+ <TrailingKeyDownContext value={onKeyDown}>+ <BaseTypeahead+ {...rest}+ ref={useMergedRefs(inputRef, ref)}+ searchSource={isAtMax ? emptySource : filteredSource}+ value={null}+ onChange={handleAdd}+ renderItem={renderItem}+ // A space keeps :placeholder-shown available as the CSS-only empty+ // query signal without painting placeholder text beside tokens.+ placeholder={value.length === 0 ? placeholder : ' '}+ hasEntriesOnFocus={isAtMax ? false : hasEntriesOnFocus}+ maxMenuItems={maxMenuItems}+ menuWidth={menuWidth}+ minQueryLength={minQueryLength}+ emptySearchText={emptySearchText}+ isDisabled={isDisabled}+ isFocusableDisabled={showsDisabledMessage}+ hasAutoFocus={hasAutoFocus}+ inputId={inputId}+ ariaDescribedBy={+ [ariaDescribedByProp, ariaDescribedBy]+ .filter(Boolean)+ .join(' ') || undefined+ }+ onChangeQuery={onChangeQuery}+ __queryEntries={createEntries}+ debounceMs={debounceMs}+ onKeyDown={handleKeyDown}+ anchorRef={wrapperRef}+ size={size}+ inputXStyle={[+ isAtMax || isTruncated+ ? styles.inputAtMax+ : value.length > 0+ ? [styles.inputCompact, compactInputSizeStyles[size]]+ : undefined,+ // The compact-token style owns the same reserve with an empty-query+ // exception. This standalone rule is only for an empty Tokenizer;+ // it still resolves to zero until the lane publishes a width.+ !(isAtMax || isTruncated || value.length > 0) && laneReserve,+ ]}+ />+ </TrailingKeyDownContext></BusyIndicatorLaneProvider>{htmlName != null &&value.map(item => (@@ -1081,7 +1121,10 @@ export function Tokenizer<T extends SearchableItem>({!isDisabled &&inputStatusHoverShadowStyles[status.type],status && inputStatusFocusWithinStyles[status.type],+ controlXstyle,),+ controlClassName,+ controlStyle,)}>{isTruncated && (<>@@ -1124,8 +1167,7 @@ export function Tokenizer<T extends SearchableItem>({return (<Field- {...rest}- ref={ref}+ {...container}label={label}isLabelHidden={isLabelHidden}description={description}@@ -1145,10 +1187,7 @@ export function Tokenizer<T extends SearchableItem>({}statusVariant={statusVariant}labelTooltip={labelTooltip}- width={width}- xstyle={xstyle}- className={className}- style={style}>+ width={width}>{tokenizerContent}{showsDisabledMessage &&disabledMessageTooltip.renderTooltip(disabledMessage)}diff --git a/packages/core/src/Typeahead/BaseTypeahead.tsx b/packages/core/src/Typeahead/BaseTypeahead.tsxindex 5153617c20..225cfda2ee 100644--- a/packages/core/src/Typeahead/BaseTypeahead.tsx+++ b/packages/core/src/Typeahead/BaseTypeahead.tsx@@ -28,6 +28,7 @@ import React, {} from 'react';import * as stylex from '@stylexjs/stylex';import {useBusyIndicatorLane} from './busyIndicatorLane';+import {useTrailingKeyDown} from './trailingKeyDown';import type {StyleXStyles} from '@stylexjs/stylex';import {usePopover} from '../Popover/usePopover';import {useAnnounce} from '../hooks/useAnnounce';@@ -990,6 +991,7 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({);// Keyboard navigation+ const trailingKeyDown = useTrailingKeyDown();const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {externalOnKeyDown?.(e);@@ -1165,7 +1167,14 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({onFocus={composeEventHandlers(handleFocus, onFocusProp)}onClick={composeEventHandlers(handleClick, onClickProp)}onBlur={composeEventHandlers(handleBlur, onBlurProp)}- onKeyDown={handleKeyDown}+ onKeyDown={+ trailingKeyDown+ ? event => {+ handleKeyDown(event);+ trailingKeyDown(event);+ }+ : handleKeyDown+ }placeholder={placeholder}// When a disabled-reason tooltip is shown the input keeps focusability// via aria-disabled + readOnly instead of the native disableddiff --git a/packages/core/src/Typeahead/Typeahead.doc.mjs b/packages/core/src/Typeahead/Typeahead.doc.mjsindex fd08aaa2ae..ffe9cafaed 100644--- a/packages/core/src/Typeahead/Typeahead.doc.mjs+++ b/packages/core/src/Typeahead/Typeahead.doc.mjs@@ -278,10 +278,36 @@ export const docs = {description: 'SVG icon component displayed at the start of the input.',},{- name: 'xstyle',+ name: 'containerXstyle',type: 'StyleXStyles',description:- 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value: not an inline style object like style={{}}.',+ 'StyleX styles for the field container (label, control, and status together). No effect inside InputGroup (style the InputGroup instead) or in a `horizontal-labels` FormLayout. Root `xstyle`, `className`, and `style` are not accepted.',+ },+ {+ name: 'containerClassName',+ type: 'string',+ description: 'Class name for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'containerStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',+ },+ {+ name: 'controlXstyle',+ type: 'StyleXStyles',+ description:+ 'StyleX styles for the visual control box: the element that paints the border and background and holds icons and end controls. Never the native input.',+ },+ {+ name: 'controlClassName',+ type: 'string',+ description: 'Class name for the visual control box.',+ },+ {+ name: 'controlStyle',+ type: 'CSSProperties',+ description: 'Inline styles for the visual control box.',},],components: [{name: 'BaseTypeahead'}, {name: 'TypeaheadItem'}],diff --git a/packages/core/src/Typeahead/Typeahead.fr10.test.tsx b/packages/core/src/Typeahead/Typeahead.fr10.test.tsxnew file mode 100644index 0000000000..163f0a056b--- /dev/null+++ b/packages/core/src/Typeahead/Typeahead.fr10.test.tsx@@ -0,0 +1,28 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it} from 'vitest';+import {screen} from '@testing-library/react';+import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';+import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';+import type {SearchableItem} from './types';+import {Typeahead, type TypeaheadProps} from './Typeahead';++describe('Typeahead props type (family:input-fields FR10)', () => {+ it('accepts container* and control* and no root styling', () => {+ expectFieldInputProps<TypeaheadProps<SearchableItem>>();+ });+});++describeFieldInputParts('Typeahead', {+ renderMember: props => (+ <Typeahead+ label="Fruit"+ searchSource={{search: () => [], bootstrap: () => []}}+ value={null}+ onChange={() => {}}+ {...props}+ />+ ),+ getControl: () => screen.getByRole('combobox'),+ inGroup: true,+});diff --git a/packages/core/src/Typeahead/Typeahead.test.tsx b/packages/core/src/Typeahead/Typeahead.test.tsxindex ff1c285d9f..2e65fbd1ef 100644--- a/packages/core/src/Typeahead/Typeahead.test.tsx+++ b/packages/core/src/Typeahead/Typeahead.test.tsx@@ -738,20 +738,19 @@ describe('Typeahead', () => {expect(onChange).toHaveBeenCalledWith(null);});- it('forwards DOM props and ref while preserving edit and blur behavior', async () => {- const ref = createRef<HTMLDivElement>();+ it('forwards DOM props and ref to the combobox input while preserving edit and blur behavior', async () => {+ const ref = createRef<HTMLInputElement>();const onClick = vi.fn();const onBlur = vi.fn();const onChange = vi.fn();- render(+ const {container} = render(<Typeaheadref={ref}id="fruit-field"data-tracking="fruit-picker"- data-testid="fruit-surface"- aria-label="Picker region"- className="custom-typeahead"- style={{marginTop: 7}}+ data-testid="fruit-input"+ containerClassName="custom-typeahead"+ containerStyle={{marginTop: 7}}label="Fruit"searchSource={fruitSource}value={fruits[0]}@@ -761,16 +760,22 @@ describe('Typeahead', () => {debounceMs={0}/>,);- const surface = screen.getByTestId('fruit-surface');+ const surface = container.querySelector<HTMLElement>('.astryx-typeahead')!;const input = screen.getByRole('combobox');- expect(ref.current).toHaveClass('astryx-field');- expect(surface).toHaveClass('astryx-typeahead');+ expect(ref.current).toBe(input);+ expect(screen.getByTestId('fruit-input')).toBe(input);+ expect(input).toHaveAttribute('id', 'fruit-field');+ expect(input).toHaveAttribute('data-tracking', 'fruit-picker');expect(input).toHaveAccessibleName('Fruit');+ const fieldRoot = container.querySelector('.custom-typeahead');+ expect(fieldRoot).toHaveClass('astryx-field');+ expect(fieldRoot).toHaveStyle({marginTop: '7px'});fireEvent.click(surface);await waitFor(() => expect(input).toHaveFocus());expect(input).toHaveValue('Apple');+ fireEvent.click(input);expect(onClick).toHaveBeenCalledOnce();fireEvent.blur(input);@@ -778,21 +783,19 @@ describe('Typeahead', () => {expect(onChange).not.toHaveBeenCalled();});- it('forwards DOM props and ref inside InputGroup without replacing built-in handlers', async () => {- const ref = createRef<HTMLDivElement>();+ it('forwards DOM props and ref to the input inside InputGroup, with control* on the surface', async () => {+ const ref = createRef<HTMLInputElement>();const onClick = vi.fn();const onBlur = vi.fn();const onChange = vi.fn();- render(+ const {container} = render(<InputGroup label="Produce"><Typeaheadref={ref}id="fruit-field"data-tracking="fruit-picker"- data-testid="fruit-surface"- aria-label="Picker region"- className="custom-typeahead"- style={{marginTop: 7}}+ controlClassName="custom-typeahead"+ controlStyle={{marginTop: 7}}label="Fruit"searchSource={fruitSource}value={fruits[0]}@@ -803,20 +806,20 @@ describe('Typeahead', () => {/></InputGroup>,);- const surface = screen.getByTestId('fruit-surface');+ const surface = container.querySelector<HTMLElement>('.astryx-typeahead')!;const input = screen.getByRole('combobox');- expect(ref.current).toBe(surface);- expect(surface).toHaveAttribute('id', 'fruit-field');- expect(surface).toHaveAttribute('data-tracking', 'fruit-picker');- expect(surface).toHaveAttribute('aria-label', 'Picker region');- expect(surface).toHaveClass('astryx-typeahead', 'custom-typeahead');+ expect(ref.current).toBe(input);+ expect(input).toHaveAttribute('id', 'fruit-field');+ expect(input).toHaveAttribute('data-tracking', 'fruit-picker');+ expect(surface).toHaveClass('custom-typeahead');expect(surface).toHaveStyle({marginTop: '7px'});expect(input).toHaveAccessibleName('Produce Fruit');fireEvent.click(surface);await waitFor(() => expect(input).toHaveFocus());expect(input).toHaveValue('Apple');+ fireEvent.click(input);expect(onClick).toHaveBeenCalledOnce();fireEvent.blur(input);@@ -2320,3 +2323,69 @@ describe('emptySearchText rename', () => {});});});++describe('Typeahead consumer key handler order', () => {+ it('runs onKeyDown on the input after built-in key handling, so it cannot cancel navigation', async () => {+ let currentTarget: EventTarget | null = null;+ const onKeyDown = vi.fn((event: React.KeyboardEvent) => {+ currentTarget = event.currentTarget;+ event.preventDefault();+ });+ const {container} = render(+ <Typeahead+ label="Fruit"+ searchSource={fruitSource}+ value={null}+ onChange={() => {}}+ debounceMs={0}+ hasEntriesOnFocus+ onKeyDown={onKeyDown}+ />,+ );+ const input = screen.getByRole('combobox');+ fireEvent.focus(input);+ await waitFor(() => {+ expect(+ screen.getAllByRole('option', {hidden: true}).length,+ ).toBeGreaterThan(0);+ });+ fireEvent.keyDown(input, {key: 'ArrowDown'});+ expect(onKeyDown).toHaveBeenCalledOnce();+ expect(currentTarget).toBe(screen.getByRole('combobox'));+ expect(input).toHaveAttribute('aria-activedescendant');+ });+});++describe('Typeahead consumer key handler target', () => {+ it('still runs onKeyDown for keys on the clear button', () => {+ const onKeyDown = vi.fn();+ render(+ <Typeahead+ label="Fruit"+ searchSource={fruitSource}+ value={fruits[0]}+ onChange={() => {}}+ onKeyDown={onKeyDown}+ />,+ );+ fireEvent.keyDown(screen.getByRole('button', {name: /clear/i}), {+ key: 'Enter',+ });+ expect(onKeyDown).toHaveBeenCalledOnce();+ });++ it('runs onKeyDown once for a key on the input', () => {+ const onKeyDown = vi.fn();+ render(+ <Typeahead+ label="Fruit"+ searchSource={fruitSource}+ value={null}+ onChange={() => {}}+ onKeyDown={onKeyDown}+ />,+ );+ fireEvent.keyDown(screen.getByRole('combobox'), {key: 'a'});+ expect(onKeyDown).toHaveBeenCalledOnce();+ });+});diff --git a/packages/core/src/Typeahead/Typeahead.tsx b/packages/core/src/Typeahead/Typeahead.tsxindex 265a6b73a9..9004afadaa 100644--- a/packages/core/src/Typeahead/Typeahead.tsx+++ b/packages/core/src/Typeahead/Typeahead.tsx@@ -59,7 +59,11 @@ import {isImeKeyEvent,mergeProps,} from '../utils';-import type {BaseProps} from '../BaseProps';+import {TrailingKeyDownContext} from './trailingKeyDown';+import {+ type FieldInputBaseProps,+ useFieldInputStyling,+} from '../Field/fieldParts';import type {SizeValue} from '../utils/types';import type {SearchableItem, SearchSource} from './types';import {themeProps} from '../utils/themeProps';@@ -75,10 +79,18 @@ export type {export type TypeaheadSize = 'sm' | 'md' | 'lg';export interface TypeaheadProps<T extends SearchableItem> extends Omit<- BaseProps<HTMLDivElement>,- 'onChange'+ FieldInputBaseProps<HTMLInputElement>,+ 'onChange' | 'onKeyDown'> {- ref?: React.Ref<HTMLDivElement>;+ /**+ * Key handler. Runs after the built-in key handling, so it observes every key+ * and cannot cancel navigation, selection, or token editing. It receives keys+ * on the combobox input and on the field's other controls (the clear button+ * and tokens).+ */+ onKeyDown?: React.KeyboardEventHandler<HTMLElement>;+ /** Ref forwarded to the combobox input. */+ ref?: React.Ref<HTMLInputElement>;/** Accessible label (required). */label: string;/** Visually hide the label. @default false */@@ -397,18 +409,27 @@ export function Typeahead<T extends SearchableItem>({debounceMs,onChangeQuery,onOpenChange,- onClick,- onBlur,+ onKeyDown,width,- xstyle,- className,- style,- 'data-testid': testId,- ...rest+ containerXstyle,+ containerClassName,+ containerStyle,+ controlXstyle,+ controlClassName,+ controlStyle,+ id: idProp,+ 'aria-describedby': ariaDescribedByProp,+ ...restProps}: TypeaheadProps<T>) {+ const {rest, container} = useFieldInputStyling('Typeahead', restProps, {+ containerXstyle,+ containerClassName,+ containerStyle,+ });const t = useTranslator();const size = useSize(sizeProp, 'md');- const inputId = useId();+ const generatedInputId = useId();+ const inputId = idProp ?? generatedInputId;const inputLabelId = useId();const descriptionId = useId();const statusMessageId = useId();@@ -579,21 +600,17 @@ export function Typeahead<T extends SearchableItem>({const typeaheadContent = (<><div- {...(inputGroup ? rest : undefined)}- ref={useMergedRefs(- wrapperRef,- disabledMessageTooltip.ref,- inputGroup ? ref : undefined,- )}- data-testid={testId}- onClick={composeEventHandlers(- handleWrapperClick,- inputGroup ? onClick : undefined,- )}- onBlur={composeEventHandlers(- handleBlur,- inputGroup ? onBlur : undefined,- )}+ ref={useMergedRefs(wrapperRef, disabledMessageTooltip.ref)}+ onClick={handleWrapperClick}+ onBlur={handleBlur}+ // Keys on the field's other controls (clear button, tokens) reach a+ // consumer onKeyDown here; keys on the input reach it through+ // TrailingKeyDownContext after the built-in handling.+ onKeyDown={event => {+ if (event.target !== inputRef.current) {+ onKeyDown?.(event);+ }+ }}{...mergeProps(themeProps('typeahead', {size, status: status?.type}),stylex.props(@@ -605,10 +622,10 @@ export function Typeahead<T extends SearchableItem>({status && inputStatusFocusWithinStyles[status.type],isDisabled && inputWrapperStyles.disabled,inputGroup && groupStyles.inGroup,- inputGroup && xstyle,+ controlXstyle,),- inputGroup ? className : undefined,- inputGroup ? style : undefined,+ controlClassName,+ controlStyle,)}>{startIcon &&renderIconSlot(startIcon, {size: 'sm', color: 'secondary'})}@@ -630,37 +647,44 @@ export function Typeahead<T extends SearchableItem>({xstyle={styles.tokenOverlay}/>)}- <BaseTypeahead- ref={inputRef}- searchSource={searchSource}- value={value}- onChange={handleChange}- renderItem={renderItem}- placeholder={showToken ? undefined : placeholder}- hasEntriesOnFocus={hasEntriesOnFocus}- maxMenuItems={maxMenuItems}- minQueryLength={minQueryLength}- emptySearchText={emptySearchText}- isDisabled={isDisabled}- hasAutoFocus={hasAutoFocus}- isFocusableDisabled={showsDisabledMessage}- inputId={inputId}- ariaDescribedBy={ariaDescribedBy}- ariaLabelledBy={ariaLabelledBy}- onChangeQuery={onChangeQuery}- onOpenChange={onOpenChange}- debounceMs={debounceMs}- anchorRef={wrapperRef}- onKeyDown={handleKeyDown}- inputXStyle={showToken ? styles.inputHidden : undefined}- // While the token is shown the input is invisible and inert behind- // it — take it out of the Tab order so keyboard users don't hit a- // stop they cannot see (WCAG 2.4.3 / 2.4.7). It stays- // programmatically focusable: entering edit mode and clearing both- // refocus it once the token goes away.- inputTabIndex={showToken ? -1 : undefined}- size={size}- />+ <TrailingKeyDownContext value={onKeyDown}>+ <BaseTypeahead+ {...rest}+ ref={useMergedRefs(inputRef, ref)}+ searchSource={searchSource}+ value={value}+ onChange={handleChange}+ renderItem={renderItem}+ placeholder={showToken ? undefined : placeholder}+ hasEntriesOnFocus={hasEntriesOnFocus}+ maxMenuItems={maxMenuItems}+ minQueryLength={minQueryLength}+ emptySearchText={emptySearchText}+ isDisabled={isDisabled}+ hasAutoFocus={hasAutoFocus}+ isFocusableDisabled={showsDisabledMessage}+ inputId={inputId}+ ariaDescribedBy={+ [ariaDescribedByProp, ariaDescribedBy]+ .filter(Boolean)+ .join(' ') || undefined+ }+ ariaLabelledBy={ariaLabelledBy}+ onChangeQuery={onChangeQuery}+ onOpenChange={onOpenChange}+ debounceMs={debounceMs}+ anchorRef={wrapperRef}+ onKeyDown={handleKeyDown}+ inputXStyle={showToken ? styles.inputHidden : undefined}+ // While the token is shown the input is invisible and inert behind+ // it — take it out of the Tab order so keyboard users don't hit a+ // stop they cannot see (WCAG 2.4.3 / 2.4.7). It stays+ // programmatically focusable: entering edit mode and clearing both+ // refocus it once the token goes away.+ inputTabIndex={showToken ? -1 : undefined}+ size={size}+ />+ </TrailingKeyDownContext></div></BusyIndicatorLaneProvider><EndLane@@ -690,10 +714,7 @@ export function Typeahead<T extends SearchableItem>({return (<Field- {...rest}- onClick={onClick}- onBlur={onBlur}- ref={ref}+ {...container}label={label}isLabelHidden={isLabelHidden}description={description}@@ -713,10 +734,7 @@ export function Typeahead<T extends SearchableItem>({}statusVariant={statusVariant}labelTooltip={labelTooltip}- width={width}- xstyle={xstyle}- className={className}- style={style}>+ width={width}>{typeaheadContent}</Field>);diff --git a/packages/core/src/Typeahead/trailingKeyDown.tsx b/packages/core/src/Typeahead/trailingKeyDown.tsxnew file mode 100644index 0000000000..485f485e53--- /dev/null+++ b/packages/core/src/Typeahead/trailingKeyDown.tsx@@ -0,0 +1,27 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++'use client';++/**+ * @file trailingKeyDown.tsx+ * @input React context+ * @output Exports TrailingKeyDownContext and useTrailingKeyDown+ * @position Package-internal; not exported from the package entry point.+ * Typeahead and Tokenizer pass a consumer `onKeyDown` through it so+ * BaseTypeahead calls it on the combobox input after its own key handling:+ * the consumer observes every key on the input and cannot cancel built-in+ * navigation, selection, or token editing (family:input-fields FR10).+ */++import {createContext, use, type KeyboardEvent} from 'react';++export type TrailingKeyDown =+ ((event: KeyboardEvent<HTMLInputElement>) => void) | undefined;++export const TrailingKeyDownContext = createContext<TrailingKeyDown>(undefined);+TrailingKeyDownContext.displayName = 'TrailingKeyDownContext';++/** The consumer key handler BaseTypeahead runs after its own, if any. */+export function useTrailingKeyDown(): TrailingKeyDown {+ return use(TrailingKeyDownContext);+}