An open source design system that's fully customizable and agent ready
TypeScript
feat(TextInput,TextArea): tell a touch keyboard what the field holds (#8166)
Christopher Chedeaued4b4afc0178
diff --git a/.changeset/text-fields-keyboard-traits.md b/.changeset/text-fields-keyboard-traits.mdnew file mode 100644index 0000000000..afe502bc9f--- /dev/null+++ b/.changeset/text-fields-keyboard-traits.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] TextInput and TextArea tell a touch keyboard what the field holds. New props `enterKeyHint` (what the Return key says: Search, Send, Next, Go, Done), `inputMode` (which keyboard: number pad, decimal pad, phone pad, web search, email, URL), `autoCapitalize` and `hasAutoCorrect`, plus `hasSpellCheck` on TextInput (TextArea already had it). TextInput's `type` also accepts `search`, `tel` and `url`. The value types are the new exported closed unions `EnterKeyHint`, `InputMode` and `AutoCapitalize`, so TypeScript rejects any other value. Each prop renders the native attribute of the same name and nothing when unset, so existing fields keep the browser's defaults.++@vjeuxdiff --git a/apps/storybook/stories/TextArea.stories.tsx b/apps/storybook/stories/TextArea.stories.tsxindex 8f9068ec62..c736050adc 100644--- a/apps/storybook/stories/TextArea.stories.tsx+++ b/apps/storybook/stories/TextArea.stories.tsx@@ -796,3 +796,35 @@ export const VerticalFormAlignment: Story = {);},};++/**+ * Keyboard traits: a note that keeps Return as a line break but turns+ * correction off for code-like text, and a caption field that capitalizes+ * every word. Focus them on a phone to see the keyboard.+ */+export const KeyboardTraits: Story = {+ render: () => {+ const [snippet, setSnippet] = useState('');+ const [caption, setCaption] = useState('');+ return (+ <div+ style={{display: 'flex', flexDirection: 'column', gap: 16, width: 320}}>+ <TextArea+ label="Shell command"+ value={snippet}+ onChange={setSnippet}+ autoCapitalize="none"+ hasAutoCorrect={false}+ hasSpellCheck={false}+ />+ <TextArea+ label="Photo caption"+ value={caption}+ onChange={setCaption}+ rows={2}+ autoCapitalize="words"+ />+ </div>+ );+ },+};diff --git a/apps/storybook/stories/TextInput.stories.tsx b/apps/storybook/stories/TextInput.stories.tsxindex f487cba727..14ff5a3632 100644--- a/apps/storybook/stories/TextInput.stories.tsx+++ b/apps/storybook/stories/TextInput.stories.tsx@@ -566,3 +566,70 @@ export const StatusVariantComparison: Story = {);},};++/**+ * Keyboard traits: what each field tells a touch keyboard. On a phone, focus+ * each field to see its keyboard and its Return key: a Search key that does+ * not capitalize, the phone pad, the URL keyboard with Go, the number pad for+ * a one-time code, and a username field that neither capitalizes nor corrects.+ */+export const KeyboardTraits: Story = {+ render: () => {+ const [query, setQuery] = useState('');+ const [phone, setPhone] = useState('');+ const [website, setWebsite] = useState('');+ const [code, setCode] = useState('');+ const [username, setUsername] = useState('');+ return (+ <div+ style={{display: 'flex', flexDirection: 'column', gap: 16, width: 320}}>+ <TextInput+ label="Search"+ type="search"+ value={query}+ onChange={setQuery}+ startIcon={MagnifyingGlassIcon}+ enterKeyHint="search"+ autoCapitalize="none"+ hasAutoCorrect={false}+ hasClear+ />+ <TextInput+ label="Phone"+ type="tel"+ value={phone}+ onChange={setPhone}+ autoComplete="tel"+ enterKeyHint="next"+ />+ <TextInput+ label="Website"+ type="url"+ value={website}+ onChange={setWebsite}+ autoComplete="url"+ enterKeyHint="go"+ />+ <TextInput+ label="Verification code"+ value={code}+ onChange={setCode}+ inputMode="numeric"+ autoComplete="one-time-code"+ enterKeyHint="done"+ />+ <TextInput+ label="Username"+ value={username}+ onChange={setUsername}+ startIcon={UserIcon}+ autoComplete="username"+ autoCapitalize="none"+ hasAutoCorrect={false}+ hasSpellCheck={false}+ enterKeyHint="next"+ />+ </div>+ );+ },+};diff --git a/docs/specs/components/TextArea/TextArea.spec.md b/docs/specs/components/TextArea/TextArea.spec.mdindex aa2dc4efc8..5ea5d133c8 100644--- a/docs/specs/components/TextArea/TextArea.spec.md+++ b/docs/specs/components/TextArea/TextArea.spec.md@@ -52,15 +52,15 @@ system_specs: [spec:AST-085, spec:AST-086]## Contract at a glance-| Area | Contract |-| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Public contract | TextArea is a controlled multi-line field with Field props, `rows`, size, status, start icon, `maxLength` counter, `onChange`, `changeAction`, `isLoading`, disabled and read-only states, `hasSpellCheck`, the touch-keyboard props `enterKeyHint`, `inputMode`, `autoCapitalize`, and `hasAutoCorrect` (FR13), and the input-family part props. |-| Behavior | Typing calls `onChange`, then an optional `changeAction` with an optimistic value and one busy Spinner. `maxLength` adds a visual character counter that warns but never blocks typing. |-| End-user impact | People write longer text with a live count that is announced only when they near or pass the limit. Keyboard and screen-reader users can reach a disabled field and its reason. An error without a message has no text. |-| Builder impact | Callers can choose the touch keyboard, its Return key label, capitalization, and correction (FR13); an unset prop leaves the field as it is. |-| Compatibility/readiness | The touch-keyboard props are additive, a patch `[feat]` (`spec:AST-017` FR5, FR7), and unbuilt (FR13 implementation gap). Otherwise the record states shipped behavior. Attached status on a tall surface, dropped grouped container props, text under the counter, an error without text, and a color-only `detached` status are listed under Current-state impact. |-| Review checks | Reject a counter that truncates input or counts code units, an announcement on every keystroke, text that runs under the icons or counter, a disabled field that leaves the tab order or submits, or root styling props. |-| Governing rules | `family:input-fields` FR4–FR6, FR8–FR10, AV3; `spec:AST-085` FR1–FR3, FR6; `spec:AST-086` FR8; `architecture:component-theming-surface`; `component:TextInput` FR16, DEC-1; `architecture:public-component-api` INV2, INV3, INV25. |+| Area | Contract |+| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Public contract | TextArea is a controlled multi-line field with Field props, `rows`, size, status, start icon, `maxLength` counter, `onChange`, `changeAction`, `isLoading`, disabled and read-only states, `hasSpellCheck`, the touch-keyboard props `enterKeyHint`, `inputMode`, `autoCapitalize`, and `hasAutoCorrect` (FR13), and the input-family part props. |+| Behavior | Typing calls `onChange`, then an optional `changeAction` with an optimistic value and one busy Spinner. `maxLength` adds a visual character counter that warns but never blocks typing. |+| End-user impact | People write longer text with a live count that is announced only when they near or pass the limit. Keyboard and screen-reader users can reach a disabled field and its reason. An error without a message has no text. |+| Builder impact | Callers can choose the touch keyboard, its Return key label, capitalization, and correction (FR13); an unset prop leaves the field as it is. |+| Compatibility/readiness | The touch-keyboard props are additive, a patch `[feat]` (`spec:AST-017` FR5, FR7). Otherwise the record states shipped behavior. Attached status on a tall surface, dropped grouped container props, text under the counter, an error without text, and a color-only `detached` status are listed under Current-state impact. |+| Review checks | Reject a counter that truncates input or counts code units, an announcement on every keystroke, text that runs under the icons or counter, a disabled field that leaves the tab order or submits, or root styling props. |+| Governing rules | `family:input-fields` FR4–FR6, FR8–FR10, AV3; `spec:AST-085` FR1–FR3, FR6; `spec:AST-086` FR8; `architecture:component-theming-surface`; `component:TextInput` FR16, DEC-1; `architecture:public-component-api` INV2, INV3, INV25. |This table is a review projection; the body below is authoritative.@@ -139,7 +139,7 @@ Consumer migration instructions belong in consumer docs and release notes.| FR10 | Read-only: `readOnly`, full opacity, focusable, still submitted, never calls `onChange`. Disabled wins when both are set. | Current tests || FR11 | `hasSpellCheck` (default on) sets `spellcheck`; `htmlName`, `autoComplete`, `hasAutoFocus`, and `onPaste` reach the textarea. A click on the container outside the textarea focuses it, except while disabled or busy. | Current tests || FR12 | Base props reach the textarea and `aria-describedby` joins TextArea's descriptions; `container*` reaches the Field box where one renders (in a `horizontal-labels` FormLayout none renders, and `container*` has no effect and warns) and `control*` the input container; root `xstyle`, `className`, and `style` are not accepted. Implementation gap: inside InputGroup the Field box still renders, but `container*` is dropped with a development warning that no Field box renders. | `family:input-fields` FR10; current tests |-| FR13 | `enterKeyHint`, `inputMode`, `autoCapitalize`, and `hasAutoCorrect` follow `component:TextInput` FR16 on the textarea: a set prop renders its native attribute (`hasAutoCorrect` as `autocorrect="on"` or `"off"`), an unset prop renders none, the value types are the same exported closed unions `EnterKeyHint`, `InputMode`, and `AutoCapitalize`, and they change only the touch keyboard. Enter inserts a line break whatever the key says. `hasSpellCheck` keeps FR11. Implementation gap: TextArea accepts none of the four props. | `component:TextInput` FR16, DEC-1 |+| FR13 | `enterKeyHint`, `inputMode`, `autoCapitalize`, and `hasAutoCorrect` follow `component:TextInput` FR16 on the textarea: a set prop renders its native attribute (`hasAutoCorrect` as `autocorrect="on"` or `"off"`), an unset prop renders none, the value types are the same exported closed unions `EnterKeyHint`, `InputMode`, and `AutoCapitalize`, and they change only the touch keyboard. Enter inserts a line break whatever the key says. `hasSpellCheck` keeps FR11. | `component:TextInput` FR16, DEC-1 |### Allowed variation@@ -256,20 +256,20 @@ FieldStatus, while the tooltip variant delegates its rendered surface to Tooltip## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |-| FR1, FR3 | `TextArea.test.tsx` structure, rows, and size cases; `inputFontFloor.test.ts` | Default, custom rows, `lg` | Removing or regrouping stable parts breaks role, content, or DOM assertions; a missing iOS floor fails. Evidence gap: no test renders TextArea inside InputGroup, or asserts vertical-only resize, the body text size, or the `lg` padding. | `audit:TextArea/anatomy` |-| FR2 | `TextArea.test.tsx` root-target and theme-state suites; `themingTargets.test.ts` | Three local targets; disabled and read-only | A missing class, a missing `data-disabled` or `data-readonly`, or source and docs drift, fails. Evidence gap: no test asserts `data-size` or `data-status`. | `audit:TextArea/theming` |-| FR4 | `TextArea.test.tsx` change and busy cases; `BusyOwnerAnnouncement.test.tsx` TextArea cases | Typing; `isLoading` | A wrong `onChange` payload, no `aria-busy`, or a busy start announced more than once fails. Evidence gap: no test asserts `changeAction` after `onChange`, or the optimistic value. | `audit:TextArea/behavior` |-| FR5, FR6, AR2, AR3 | `TextArea.test.tsx` maxLength suite | Under, near, over; emoji; controlled typing | Native truncation, code-unit counting, a missing cue, or a missing zone announcement fails. Evidence gap: no test types twice inside a zone or moves back under the limit, so a repeated announcement would pass. | `audit:TextArea/accessibility` |-| FR7, FR8 | `TextArea.test.tsx` status, busy-with-status, and statusVariant suites; `useInputStatusIcon.test.tsx` TextArea tooltip and placement cases | Attached, detached, tooltip; busy with status | A missing status icon or message, or a missing `aria-invalid` on error, fails. Evidence gap: no test measures the reserved padding or text under the counter, or renders a `detached` status without a message. | `audit:TextArea/layout` |-| FR9, FR10, ORD1, AR4 | `TextArea.test.tsx` disabled, disabledMessage, read-only, and form suites; the disabled no-caller-handler case (paste and key) | Disabled, with reason, read-only, both | A lost tab stop, a submitted disabled value, a caller handler, or an edit fails. | `audit:TextArea/accessibility` |-| FR11 | `TextArea.test.tsx` spellcheck, paste, autoComplete, autofocus, click-to-focus suites | Each prop | A dropped attribute or unfocused click fails. Evidence gap: no test clicks the container while disabled or busy. | `audit:TextArea/behavior` |-| FR12 | `TextArea.fr10.test.tsx` | Standalone; `horizontal-labels` FormLayout | A base prop off the textarea, or styling on the wrong part, fails. | `audit:TextArea/api` |-| FR13 | Evidence gap until built: render tests that each set prop reaches the textarea as its native attribute and that no attribute renders while a prop is unset; a type test that each value type rejects an arbitrary string; a real-browser touch-emulation check that the focused textarea carries the attributes | Each prop set and unset; a phone viewport with touch emulation | An attribute while unset, a dropped or renamed attribute, or a value type that accepts `string` fails. | `audit:TextArea/api` |-| ORD2, ORD3, PR1 | Evidence gap: the description cases check each id's presence, not the ORD3 order, and no test asserts the counter-zone, change, and Action order, or that counting runs only with `maxLength` | — | — | `audit:TextArea/behavior` |-| AR1 | `TextInput.a11y.test.tsx` and `TextInput.a11y.chromium.spec.ts` TextArea states | Empty with placeholder; error without message | A missing name or description fails; the recorded known failure stops matching when its gap closes. | `audit:TextArea/accessibility` |-| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current local targets | Canonical-key drift, invalid dispositions or target spelling, alias-backed local claims, or an unclaimed current local target fails validation. | `audit:TextArea/theming` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |+| FR1, FR3 | `TextArea.test.tsx` structure, rows, and size cases; `inputFontFloor.test.ts` | Default, custom rows, `lg` | Removing or regrouping stable parts breaks role, content, or DOM assertions; a missing iOS floor fails. Evidence gap: no test renders TextArea inside InputGroup, or asserts vertical-only resize, the body text size, or the `lg` padding. | `audit:TextArea/anatomy` |+| FR2 | `TextArea.test.tsx` root-target and theme-state suites; `themingTargets.test.ts` | Three local targets; disabled and read-only | A missing class, a missing `data-disabled` or `data-readonly`, or source and docs drift, fails. Evidence gap: no test asserts `data-size` or `data-status`. | `audit:TextArea/theming` |+| FR4 | `TextArea.test.tsx` change and busy cases; `BusyOwnerAnnouncement.test.tsx` TextArea cases | Typing; `isLoading` | A wrong `onChange` payload, no `aria-busy`, or a busy start announced more than once fails. Evidence gap: no test asserts `changeAction` after `onChange`, or the optimistic value. | `audit:TextArea/behavior` |+| FR5, FR6, AR2, AR3 | `TextArea.test.tsx` maxLength suite | Under, near, over; emoji; controlled typing | Native truncation, code-unit counting, a missing cue, or a missing zone announcement fails. Evidence gap: no test types twice inside a zone or moves back under the limit, so a repeated announcement would pass. | `audit:TextArea/accessibility` |+| FR7, FR8 | `TextArea.test.tsx` status, busy-with-status, and statusVariant suites; `useInputStatusIcon.test.tsx` TextArea tooltip and placement cases | Attached, detached, tooltip; busy with status | A missing status icon or message, or a missing `aria-invalid` on error, fails. Evidence gap: no test measures the reserved padding or text under the counter, or renders a `detached` status without a message. | `audit:TextArea/layout` |+| FR9, FR10, ORD1, AR4 | `TextArea.test.tsx` disabled, disabledMessage, read-only, and form suites; the disabled no-caller-handler case (paste and key) | Disabled, with reason, read-only, both | A lost tab stop, a submitted disabled value, a caller handler, or an edit fails. | `audit:TextArea/accessibility` |+| FR11 | `TextArea.test.tsx` spellcheck, paste, autoComplete, autofocus, click-to-focus suites | Each prop | A dropped attribute or unfocused click fails. Evidence gap: no test clicks the container while disabled or busy. | `audit:TextArea/behavior` |+| FR12 | `TextArea.fr10.test.tsx` | Standalone; `horizontal-labels` FormLayout | A base prop off the textarea, or styling on the wrong part, fails. | `audit:TextArea/api` |+| FR13 | `TextArea.test.tsx` touch keyboard traits suite (each prop set and unset; Return stays a line break under any `enterKeyHint`); `textEntryTraits.public.test.ts`, run by `pnpm typecheck`, for the shared unions rejecting an arbitrary or unnarrowed string; `TextAreaKeyboardTraits.a11y.chromium.spec.ts` for the attributes on the textarea a tap focuses | Each prop set and unset; a phone viewport with touch emulation | An attribute while unset, a dropped or renamed attribute, or a value type that accepts `string` fails. | `audit:TextArea/api` |+| ORD2, ORD3, PR1 | Evidence gap: the description cases check each id's presence, not the ORD3 order, and no test asserts the counter-zone, change, and Action order, or that counting runs only with `maxLength` | — | — | `audit:TextArea/behavior` |+| AR1 | `TextInput.a11y.test.tsx` and `TextInput.a11y.chromium.spec.ts` TextArea states | Empty with placeholder; error without message | A missing name or description fails; the recorded known failure stops matching when its gap closes. | `audit:TextArea/accessibility` |+| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current local targets | Canonical-key drift, invalid dispositions or target spelling, alias-backed local claims, or an unclaimed current local target fails validation. | `audit:TextArea/theming` |No repository check resolves `delegatesTo` owner and target pairs; the pairsabove match the current Field, FieldStatus, Icon, Spinner, and Tooltip targets.@@ -289,9 +289,6 @@ above match the current Field, FieldStatus, Icon, Spinner, and Tooltip targets.shared text-input accessibility suite records this as a known failure.- **Color-only detached status (FR8).** A `detached` status without a messageshows only the colored border, against WCAG 2.2 1.4.1.-- **Keyboard props unbuilt (FR13).** TextArea accepts no touch-keyboard prop- other than `hasSpellCheck`, so a caller cannot change the keyboard, its- Return key label, capitalization, or correction.## Decision logdiff --git a/docs/specs/components/TextInput/TextInput.spec.md b/docs/specs/components/TextInput/TextInput.spec.mdindex d4633512aa..cf73929625 100644--- a/docs/specs/components/TextInput/TextInput.spec.md+++ b/docs/specs/components/TextInput/TextInput.spec.md@@ -35,15 +35,15 @@ system_specs: [spec:AST-082, spec:AST-085, spec:AST-086, spec:AST-102]## Contract at a glance-| Area | Contract |-| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Public contract | TextInput is a controlled single-line text field with Field props, `type` (`text`, `password`, `email`, `search`, `tel`, `url`), size, status, clear, start icon, `onChange`, `changeAction`, `isLoading`, disabled and read-only states, the touch-keyboard props `enterKeyHint`, `inputMode`, `autoCapitalize`, `hasAutoCorrect`, and `hasSpellCheck` (FR16), and the input-family part props. |-| Behavior | Typing calls `onChange`, then an optional `changeAction` in a transition with an optimistic value, and a busy Spinner while the shown value differs from `value`. A disabled field stays focusable, read-only, unsubmitted, and inert. |-| End-user impact | People type into a labelled field that shows progress and validation in place. Keyboard and screen-reader users can reach a disabled field and its reason. An error without a message is signalled only by color and an icon. On a phone, a field its caller describes opens the keyboard it needs, such as a phone pad or a number pad, with a Return key that says Next, Go, or Done, and leaves names as typed. |-| Builder impact | Callers can choose the touch keyboard, its Return key label, capitalization, correction, and spell-check marking (FR16); an unset prop leaves the field as it is. |-| Compatibility/readiness | The touch-keyboard props and the `search`, `tel`, and `url` types are additive, a patch `[feat]` (`spec:AST-017` FR5, FR7), and unbuilt (FR16 implementation gap). Otherwise the record states shipped behavior. The clear action skips `changeAction`, the clear button scales under reduced motion, an error may lack text, the height does not grow with text, a `detached` status without a message is color-only, and a grouped `description` is referenced but not rendered; all are listed under Current-state impact. |-| Review checks | Reject a disabled field that leaves the tab order, submits, or runs caller handlers; an Enter that fires `onEnter` while committing an IME conversion; a busy state without `aria-busy`; root styling props; a keyboard prop that renders an attribute while unset or changes what Enter does; or a keyboard value type that accepts any string. |-| Governing rules | `family:input-fields` FR1, FR2, FR3, FR4, FR6, FR8–FR11; `spec:AST-085` FR1–FR3, FR5–FR7; `spec:AST-086` FR8; `architecture:component-size-cascade` INV3–INV5; `design:reduced-motion` DR1; `spec:AST-102` FR4; `architecture:public-component-api` INV2–INV4, INV25; `spec:AST-082` FR3, DEC-14; `spec:AST-017` FR5, FR7. |+| Area | Contract |+| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Public contract | TextInput is a controlled single-line text field with Field props, `type` (`text`, `password`, `email`, `search`, `tel`, `url`), size, status, clear, start icon, `onChange`, `changeAction`, `isLoading`, disabled and read-only states, the touch-keyboard props `enterKeyHint`, `inputMode`, `autoCapitalize`, `hasAutoCorrect`, and `hasSpellCheck` (FR16), and the input-family part props. |+| Behavior | Typing calls `onChange`, then an optional `changeAction` in a transition with an optimistic value, and a busy Spinner while the shown value differs from `value`. A disabled field stays focusable, read-only, unsubmitted, and inert. |+| End-user impact | People type into a labelled field that shows progress and validation in place. Keyboard and screen-reader users can reach a disabled field and its reason. An error without a message is signalled only by color and an icon. On a phone, a field its caller describes opens the keyboard it needs, such as a phone pad or a number pad, with a Return key that says Next, Go, or Done, and leaves names as typed. |+| Builder impact | Callers can choose the touch keyboard, its Return key label, capitalization, correction, and spell-check marking (FR16); an unset prop leaves the field as it is. |+| Compatibility/readiness | The touch-keyboard props and the `search`, `tel`, and `url` types are additive, a patch `[feat]` (`spec:AST-017` FR5, FR7). Otherwise the record states shipped behavior. The clear action skips `changeAction`, the clear button scales under reduced motion, an error may lack text, the height does not grow with text, a `detached` status without a message is color-only, and a grouped `description` is referenced but not rendered; all are listed under Current-state impact. |+| Review checks | Reject a disabled field that leaves the tab order, submits, or runs caller handlers; an Enter that fires `onEnter` while committing an IME conversion; a busy state without `aria-busy`; root styling props; a keyboard prop that renders an attribute while unset or changes what Enter does; or a keyboard value type that accepts any string. |+| Governing rules | `family:input-fields` FR1, FR2, FR3, FR4, FR6, FR8–FR11; `spec:AST-085` FR1–FR3, FR5–FR7; `spec:AST-086` FR8; `architecture:component-size-cascade` INV3–INV5; `design:reduced-motion` DR1; `spec:AST-102` FR4; `architecture:public-component-api` INV2–INV4, INV25; `spec:AST-082` FR3, DEC-14; `spec:AST-017` FR5, FR7. |This table is a review projection; the body below is authoritative.@@ -112,24 +112,24 @@ Consumer migration instructions belong in consumer docs and release notes.## Behavioral and layout contract-| ID | Invariant | Basis |-| ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |-| FR1 | Standalone, TextInput renders inside Field with its label (always rendered; `isLabelHidden` hides it visually), description, optional or required marker, label tooltip, status, and `width`. Inside InputGroup it renders no Field: `aria-labelledby` names the input by the group label, then a visually hidden label inside the control, and no status message box renders. | `family:input-fields` FR3; current source and tests |-| FR2 | The input is a native `<input>` of the chosen `type` showing the controlled value. `htmlName` becomes `name`, `autoComplete` reaches the input unchanged, and `hasAutoFocus` focuses it on mount. | Current tests |-| FR3 | Editing calls `onChange(value, event)`. Unless that call prevents default, `changeAction(value, event)` then runs in a transition; the field shows the proposed value while the Action is pending, and the controlled `value` once it settles. | `family:input-fields` FR6; current source |-| FR4 | While `isLoading` or while the shown value differs from `value`, the input sets `aria-busy`, a decorative small Spinner shows in the end area, and the busy start is announced once (`spec:AST-086` FR8). | `family:input-fields` FR5; `spec:AST-086` FR8; current source |-| FR5 | With `hasClear`, a clear button shows only while `value` is non-empty and the field is editable. Its accessible name is the localized "Clear" phrase with the label. Activating it MUST commit `''` through FR3's pipeline (`onChange`, then the optimistic value and `changeAction`) and moves focus to the input: at once for keyboard activation, and inside the tap without scrolling for pointer activation. The clear button is a ghost small `component:Button`, so its press feedback follows Button FR15, whose press scale MUST NOT apply under reduced motion (`design:reduced-motion` DR1). Implementation gap: it calls only `onChange('')`, with no event, and skips the optimistic value and `changeAction`; and its press scale still applies under reduced motion. | `family:input-fields` FR6, FR11; current tests |-| FR6 | TextInput is disabled when its own `isDisabled` or an enclosing InputGroup's `isDisabled` is true; an enabled group never re-enables a field that disables itself (`spec:AST-085` FR7). Disabled: the input exposes `aria-disabled="true"` and `readOnly`, keeps its tab stop, has no `name` (so it does not submit), and never changes value. Caller event handlers other than focus and blur do not run, Enter is cancelled, the clear button hides, the control dims, and keyboard focus paints a ring. | `spec:AST-085` FR1–FR3, FR6; current tests |-| FR7 | Disabled with `disabledMessage`: a tooltip with the reason opens above the control on hover and keyboard focus, and describes the input. | `family:input-fields` FR4; current tests |-| FR8 | Read-only: the input is `readOnly`, keeps full opacity, stays focusable, still submits under `name`, never calls `onChange`, and hides the clear button. Disabled wins when both are set. | Current tests |-| FR9 | A status paints the status border; `error` sets `aria-invalid="true"`. Outside InputGroup, `attached` and `tooltip` placement show a trailing status icon on the control; `detached` placement shows its glyph only in the message box, which renders only with a message; inside InputGroup no status icon renders. Outside InputGroup, a message renders through Field in the chosen placement; `tooltip` renders no message box, and with a message its status icon becomes a focusable button whose tooltip describes the input (without one it stays a plain icon). | `family:input-fields` FR8; current tests |-| FR10 | Enter calls `onEnter` unless the key event commits an IME composition; `onKeyDown` receives every key, including composing ones. | Current tests |-| FR11 | Standalone, height comes from the shared element size for the resolved size, as a minimum that grows with a set text size under `spec:AST-102` FR4: explicit `size`, then the nearest size provider, then `md`. Implementation gap: the height is fixed at that size. Inside InputGroup the control fills the group row's height, so its own `size` does not set its height. Text uses the body type size at every size, floored at 16 CSS px only on the iOS touch path. | `family:input-fields` FR9; `architecture:component-size-cascade`; current source and tests; `spec:AST-102` FR4 |-| FR12 | `startIcon` renders a small secondary icon before the input. While the field is enabled, a click on the control box outside the input focuses the input. | Current tests |-| FR13 | Base props (`ref`, `id`, `aria-*`, `data-*`, DOM handlers, and the like) reach the native input; `aria-describedby` is joined with TextInput's own descriptions, and `aria-labelledby` follows the field's own label (AR1). `container*` reaches the Field box and `control*` the control box. Root `xstyle`, `className`, and `style` are not accepted; an untyped one is dropped with a development warning. | `family:input-fields` FR10; current tests |-| FR14 | The control box carries `astryx-text-input` and reflects `data-size`, `data-status` when set, `data-disabled` when disabled, and `data-readonly` when read-only. | `architecture:component-theming-surface`; current tests |-| FR15 | The input has no minimum inline size, so a row can shrink the whole field. End controls (clear, Spinner, status icon) are in-flow items after the input and never overlap its text. | `family:input-fields` FR1, FR2; current tests |-| FR16 | `enterKeyHint`, `inputMode`, `autoCapitalize`, `hasAutoCorrect`, and `hasSpellCheck` are optional. A set prop renders its native attribute on the input: `enterkeyhint`, `inputmode`, `autocapitalize`, `autocorrect="on"` or `"off"`, and `spellcheck="true"` or `"false"`; an unset prop renders no attribute, so the browser keeps its own keyboard. `enterKeyHint`, `inputMode`, and `autoCapitalize` take the closed unions `EnterKeyHint`, `InputMode`, and `AutoCapitalize`, exported from the package entry with no `string` widening, so TypeScript rejects any other value; `hasAutoCorrect` and `hasSpellCheck` are on/off booleans. They choose only the touch keyboard, its Return key label, capitalization, correction, and spell-check marking: Enter follows FR10 whatever the key says, and the value, validation, and submission do not change. They and the `search`, `tel`, and `url` types belong to the web contract; the Swift contract carries one only where its field applies it (`component:swift/TextInput` FR6). Implementation gap: TextInput accepts none of these props, the three value types are not exported, and `type` accepts only `text`, `password`, and `email`. | DEC-1; `architecture:public-component-api` INV2, INV3, INV25; `spec:AST-082` FR3, DEC-14 |+| ID | Invariant | Basis |+| ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |+| FR1 | Standalone, TextInput renders inside Field with its label (always rendered; `isLabelHidden` hides it visually), description, optional or required marker, label tooltip, status, and `width`. Inside InputGroup it renders no Field: `aria-labelledby` names the input by the group label, then a visually hidden label inside the control, and no status message box renders. | `family:input-fields` FR3; current source and tests |+| FR2 | The input is a native `<input>` of the chosen `type` showing the controlled value. `htmlName` becomes `name`, `autoComplete` reaches the input unchanged, and `hasAutoFocus` focuses it on mount. | Current tests |+| FR3 | Editing calls `onChange(value, event)`. Unless that call prevents default, `changeAction(value, event)` then runs in a transition; the field shows the proposed value while the Action is pending, and the controlled `value` once it settles. | `family:input-fields` FR6; current source |+| FR4 | While `isLoading` or while the shown value differs from `value`, the input sets `aria-busy`, a decorative small Spinner shows in the end area, and the busy start is announced once (`spec:AST-086` FR8). | `family:input-fields` FR5; `spec:AST-086` FR8; current source |+| FR5 | With `hasClear`, a clear button shows only while `value` is non-empty and the field is editable. Its accessible name is the localized "Clear" phrase with the label. Activating it MUST commit `''` through FR3's pipeline (`onChange`, then the optimistic value and `changeAction`) and moves focus to the input: at once for keyboard activation, and inside the tap without scrolling for pointer activation. The clear button is a ghost small `component:Button`, so its press feedback follows Button FR15, whose press scale MUST NOT apply under reduced motion (`design:reduced-motion` DR1). Implementation gap: it calls only `onChange('')`, with no event, and skips the optimistic value and `changeAction`; and its press scale still applies under reduced motion. | `family:input-fields` FR6, FR11; current tests |+| FR6 | TextInput is disabled when its own `isDisabled` or an enclosing InputGroup's `isDisabled` is true; an enabled group never re-enables a field that disables itself (`spec:AST-085` FR7). Disabled: the input exposes `aria-disabled="true"` and `readOnly`, keeps its tab stop, has no `name` (so it does not submit), and never changes value. Caller event handlers other than focus and blur do not run, Enter is cancelled, the clear button hides, the control dims, and keyboard focus paints a ring. | `spec:AST-085` FR1–FR3, FR6; current tests |+| FR7 | Disabled with `disabledMessage`: a tooltip with the reason opens above the control on hover and keyboard focus, and describes the input. | `family:input-fields` FR4; current tests |+| FR8 | Read-only: the input is `readOnly`, keeps full opacity, stays focusable, still submits under `name`, never calls `onChange`, and hides the clear button. Disabled wins when both are set. | Current tests |+| FR9 | A status paints the status border; `error` sets `aria-invalid="true"`. Outside InputGroup, `attached` and `tooltip` placement show a trailing status icon on the control; `detached` placement shows its glyph only in the message box, which renders only with a message; inside InputGroup no status icon renders. Outside InputGroup, a message renders through Field in the chosen placement; `tooltip` renders no message box, and with a message its status icon becomes a focusable button whose tooltip describes the input (without one it stays a plain icon). | `family:input-fields` FR8; current tests |+| FR10 | Enter calls `onEnter` unless the key event commits an IME composition; `onKeyDown` receives every key, including composing ones. | Current tests |+| FR11 | Standalone, height comes from the shared element size for the resolved size, as a minimum that grows with a set text size under `spec:AST-102` FR4: explicit `size`, then the nearest size provider, then `md`. Implementation gap: the height is fixed at that size. Inside InputGroup the control fills the group row's height, so its own `size` does not set its height. Text uses the body type size at every size, floored at 16 CSS px only on the iOS touch path. | `family:input-fields` FR9; `architecture:component-size-cascade`; current source and tests; `spec:AST-102` FR4 |+| FR12 | `startIcon` renders a small secondary icon before the input. While the field is enabled, a click on the control box outside the input focuses the input. | Current tests |+| FR13 | Base props (`ref`, `id`, `aria-*`, `data-*`, DOM handlers, and the like) reach the native input; `aria-describedby` is joined with TextInput's own descriptions, and `aria-labelledby` follows the field's own label (AR1). `container*` reaches the Field box and `control*` the control box. Root `xstyle`, `className`, and `style` are not accepted; an untyped one is dropped with a development warning. | `family:input-fields` FR10; current tests |+| FR14 | The control box carries `astryx-text-input` and reflects `data-size`, `data-status` when set, `data-disabled` when disabled, and `data-readonly` when read-only. | `architecture:component-theming-surface`; current tests |+| FR15 | The input has no minimum inline size, so a row can shrink the whole field. End controls (clear, Spinner, status icon) are in-flow items after the input and never overlap its text. | `family:input-fields` FR1, FR2; current tests |+| FR16 | `enterKeyHint`, `inputMode`, `autoCapitalize`, `hasAutoCorrect`, and `hasSpellCheck` are optional. A set prop renders its native attribute on the input: `enterkeyhint`, `inputmode`, `autocapitalize`, `autocorrect="on"` or `"off"`, and `spellcheck="true"` or `"false"`; an unset prop renders no attribute, so the browser keeps its own keyboard. `enterKeyHint`, `inputMode`, and `autoCapitalize` take the closed unions `EnterKeyHint`, `InputMode`, and `AutoCapitalize`, exported from the package entry with no `string` widening, so TypeScript rejects any other value; `hasAutoCorrect` and `hasSpellCheck` are on/off booleans. They choose only the touch keyboard, its Return key label, capitalization, correction, and spell-check marking: Enter follows FR10 whatever the key says, and the value, validation, and submission do not change. They and the `search`, `tel`, and `url` types belong to the web contract; the Swift contract carries one only where its field applies it (`component:swift/TextInput` FR6). | DEC-1; `architecture:public-component-api` INV2, INV3, INV25; `spec:AST-082` FR3, DEC-14 |### Allowed variation@@ -187,8 +187,7 @@ Consumer migration instructions belong in consumer docs and release notes.message shows only the colored border.- **AR5 — Focus-zoom floor.** FR11.- **AR6 — Search field.** With `type="search"` the native input has the- searchbox role, so a screen reader announces a search field. Implementation- gap: `type` does not accept `search`.+ searchbox role, so a screen reader announces a search field.## Design relationships@@ -219,23 +218,23 @@ anatomy-theming map.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |-| FR1, AR1 | `TextInput.test.tsx` label, tooltip, and group cases; `InputGroup.test.tsx` grouped name and description cases; `TextInput.a11y.chromium.spec.ts` | Standalone, hidden label, in group | A lost name, a wrong grouped name or description, or a dangling description id fails. Evidence gap: no test asserts the optional marker or the standalone description. | `audit:TextInput/accessibility` |-| FR2, FR3 | `TextInput.test.tsx` change, form, autoComplete, autofocus cases | Typing; form submission | A wrong `onChange` payload or a missing `name` fails. Evidence gap: no test asserts the `type` or that `changeAction` runs after `onChange` with the optimistic value. | `audit:TextInput/behavior` |-| FR4 | Evidence gap: no TextInput test of the pending Action's optimistic value and busy announcement | — | — | `audit:TextInput/behavior` |-| FR5 | `TextInput.test.tsx` clear and clear-focus suites | Keyboard and pointer clear; empty; disabled | A clear button on an empty or disabled field, or lost focus, fails. Evidence gap: no test presses the clear button under reduced motion. | `audit:TextInput/behavior` |-| FR6–FR8, AR3 | `TextInput.test.tsx` disabled, disabledMessage, read-only, and form suites; `InputGroup.test.tsx` disabled-propagation cases | Disabled, with reason, read-only, both | A lost tab stop, a submitted disabled value, a caller handler, or an edit fails. Evidence gap: no test asserts the dimmed paint. | `audit:TextInput/accessibility` |-| FR9 | `TextInput.test.tsx` status and statusVariant suites | Each type; each placement; in group | A missing icon, `aria-invalid`, or description fails. Evidence gap: no test asserts the status border paint. | `audit:TextInput/accessibility` |-| FR10 | `TextInput.test.tsx` onEnter and onKeyDown suites | Enter; IME commit; other keys | `onEnter` during IME commit fails. | `audit:TextInput/behavior` |-| FR11, FR15 | `TextInput.test.tsx` text-size and narrow-row cases | Outside the iOS gate; narrow filter bar | A floor off iOS, or a field that overflows its row, fails. Evidence gap: no test asserts the height per size, the size precedence, or that end controls never overlap the text. No test asserts the grouped height. | `audit:TextInput/layout` |-| FR12 | `TextInput.test.tsx` start-icon and click-to-focus cases | Icon; wrapper padding | Clicks that do not focus the input fail. Evidence gap: no test asserts the start icon's size or color. | `audit:TextInput/behavior` |-| FR13 | `TextInput.fr10.test.tsx`; `TextInput.test.tsx` caller `aria-labelledby` cases | Standalone and in group | A base prop off the input, or styling on the wrong part, fails. | `audit:TextInput/api` |-| FR14 | `TextInput.test.tsx` theme-state suites | Disabled and read-only | A missing state attribute fails. Evidence gap: no test asserts `data-size` or `data-status`. | `audit:TextInput/theming` |-| AR4 | `TextInput.a11y.chromium.spec.ts` with its recorded known failure | Error without message | The known failure stops matching when the gap closes. Evidence gap: no test renders a `detached` status without a message. | `audit:TextInput/accessibility` |-| FR16, DEC-1 | Evidence gap until built: render tests that each set prop reaches the input as its native attribute (`hasAutoCorrect` as `autocorrect="on"` or `"off"`, `hasSpellCheck` as `spellcheck`), that no attribute renders while a prop is unset, that `type` renders `search`, `tel`, and `url`, and that Enter calls `onEnter` under every `enterKeyHint`; a type test that `EnterKeyHint`, `InputMode`, and `AutoCapitalize` are exported from the package entry and reject an arbitrary string; a real-browser touch-emulation check that the focused input carries the attributes | Each prop set and unset; each `type`; Enter under `send`; a phone viewport with touch emulation | An attribute while unset, a dropped or renamed attribute, `onEnter` skipped under any label, a value type that accepts `string`, or a missing export fails. | `audit:TextInput/api` |-| AR6 | Evidence gap until built: a role test for `type="search"` | `type="search"` | A search field without the searchbox role fails. | `audit:TextInput/accessibility` |-| ORD1–ORD3, PR1 | ORD1 and ORD2 are covered by the FR3 and FR6–FR8 rows. Evidence gap: no test asserts the description order or the absence of measurement | — | — | `audit:TextInput/behavior` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |+| FR1, AR1 | `TextInput.test.tsx` label, tooltip, and group cases; `InputGroup.test.tsx` grouped name and description cases; `TextInput.a11y.chromium.spec.ts` | Standalone, hidden label, in group | A lost name, a wrong grouped name or description, or a dangling description id fails. Evidence gap: no test asserts the optional marker or the standalone description. | `audit:TextInput/accessibility` |+| FR2, FR3 | `TextInput.test.tsx` change, form, autoComplete, autofocus cases | Typing; form submission | A wrong `onChange` payload or a missing `name` fails. Evidence gap: no test asserts the `type` or that `changeAction` runs after `onChange` with the optimistic value. | `audit:TextInput/behavior` |+| FR4 | Evidence gap: no TextInput test of the pending Action's optimistic value and busy announcement | — | — | `audit:TextInput/behavior` |+| FR5 | `TextInput.test.tsx` clear and clear-focus suites | Keyboard and pointer clear; empty; disabled | A clear button on an empty or disabled field, or lost focus, fails. Evidence gap: no test presses the clear button under reduced motion. | `audit:TextInput/behavior` |+| FR6–FR8, AR3 | `TextInput.test.tsx` disabled, disabledMessage, read-only, and form suites; `InputGroup.test.tsx` disabled-propagation cases | Disabled, with reason, read-only, both | A lost tab stop, a submitted disabled value, a caller handler, or an edit fails. Evidence gap: no test asserts the dimmed paint. | `audit:TextInput/accessibility` |+| FR9 | `TextInput.test.tsx` status and statusVariant suites | Each type; each placement; in group | A missing icon, `aria-invalid`, or description fails. Evidence gap: no test asserts the status border paint. | `audit:TextInput/accessibility` |+| FR10 | `TextInput.test.tsx` onEnter and onKeyDown suites | Enter; IME commit; other keys | `onEnter` during IME commit fails. | `audit:TextInput/behavior` |+| FR11, FR15 | `TextInput.test.tsx` text-size and narrow-row cases | Outside the iOS gate; narrow filter bar | A floor off iOS, or a field that overflows its row, fails. Evidence gap: no test asserts the height per size, the size precedence, or that end controls never overlap the text. No test asserts the grouped height. | `audit:TextInput/layout` |+| FR12 | `TextInput.test.tsx` start-icon and click-to-focus cases | Icon; wrapper padding | Clicks that do not focus the input fail. Evidence gap: no test asserts the start icon's size or color. | `audit:TextInput/behavior` |+| FR13 | `TextInput.fr10.test.tsx`; `TextInput.test.tsx` caller `aria-labelledby` cases | Standalone and in group | A base prop off the input, or styling on the wrong part, fails. | `audit:TextInput/api` |+| FR14 | `TextInput.test.tsx` theme-state suites | Disabled and read-only | A missing state attribute fails. Evidence gap: no test asserts `data-size` or `data-status`. | `audit:TextInput/theming` |+| AR4 | `TextInput.a11y.chromium.spec.ts` with its recorded known failure | Error without message | The known failure stops matching when the gap closes. Evidence gap: no test renders a `detached` status without a message. | `audit:TextInput/accessibility` |+| FR16, DEC-1 | `TextInput.test.tsx` touch keyboard traits suite (each prop set and unset, `hasAutoCorrect` and `hasSpellCheck` on and off, Enter calls `onEnter` under every `enterKeyHint`) and type suite (`search`, `tel`, and `url`); `textEntryTraits.test.ts`; `textEntryTraits.public.test.ts`, run by `pnpm typecheck`, for the unions exported from the package entry rejecting an arbitrary or unnarrowed string; `TextInputKeyboardTraits.a11y.chromium.spec.ts` for the attributes on the input a tap focuses | Each prop set and unset; each `type`; Enter under `send`; a phone viewport with touch emulation | An attribute while unset, a dropped or renamed attribute, `onEnter` skipped under any label, a value type that accepts `string`, or a missing export fails. | `audit:TextInput/api` |+| AR6 | `TextInput.test.tsx` type suite (`type="search"` renders a searchbox); `TextInputKeyboardTraits.a11y.chromium.spec.ts` | `type="search"` | A search field without the searchbox role fails. | `audit:TextInput/accessibility` |+| ORD1–ORD3, PR1 | ORD1 and ORD2 are covered by the FR3 and FR6–FR8 rows. Evidence gap: no test asserts the description order or the absence of measurement | — | — | `audit:TextInput/behavior` |## Current-state impact@@ -256,9 +255,6 @@ anatomy-theming map.records, against `design:reduced-motion` DR1.- **Fixed height (FR11).** The control holds the fixed shared element heightinstead of growing with a set text size, against `spec:AST-102` FR4.-- **Keyboard props unbuilt (FR16, AR6).** TextInput accepts no touch-keyboard- prop and only the `text`, `password`, and `email` types, so every field opens- the browser's default keyboard and a caller cannot change it.- **Source comment.** The `size` JSDoc in `TextInput.tsx` gives 18 px and 26 pxheights; the shipped heights come from the shared element sizes (FR11).diff --git a/packages/core/src/Field/index.ts b/packages/core/src/Field/index.tsindex 0ad45113a6..e4985c7546 100644--- a/packages/core/src/Field/index.ts+++ b/packages/core/src/Field/index.ts@@ -5,7 +5,8 @@/*** @file index.ts* @input Imports Field component and types from Field.tsx, FieldLabel from FieldLabel.tsx, FieldStatus from FieldStatus.tsx- * @output Exports Field, FieldProps, FieldStatusInput, FieldStatusType, FieldLabel, FieldLabelProps, FieldStatus component+ * @output Exports Field, FieldProps, FieldStatusInput, FieldStatusType, FieldLabel, FieldLabelProps, FieldStatus component,+ * and the shared input types (including the text-entry keyboard trait types)* @position Component entry point; re-exported by /packages/core/src/index.ts** SYNC: When modified, update this header and /packages/core/src/Field/Field.doc.mjs@@ -31,6 +32,7 @@ export type {FieldControlStyleProps,FieldPartStyleProps,} from './fieldParts';+export type {AutoCapitalize, EnterKeyHint, InputMode} from './textEntryTraits';// Shared input stylesexport {diff --git a/packages/core/src/Field/textEntryTraits.public.test.ts b/packages/core/src/Field/textEntryTraits.public.test.tsnew file mode 100644index 0000000000..2464dbe50d--- /dev/null+++ b/packages/core/src/Field/textEntryTraits.public.test.ts@@ -0,0 +1,95 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file textEntryTraits.public.test.ts+ * @input The package entry's keyboard-trait types and the props of the fields+ * that take them+ * @output Guards that `enterKeyHint`, `inputMode` and `autoCapitalize` are+ * closed unions of the HTML-standard values, importable from the package+ * entry, and that an arbitrary or unnarrowed string does not type-check+ * @position Public API test guarding @astryxdesign/core; `pnpm typecheck`+ * runs its type assertions+ */++import {describe, expectTypeOf, it} from 'vitest';+import type {+ TextAreaProps,+ AutoCapitalize,+ EnterKeyHint,+ InputMode,+ TextInputProps,+} from '../index';++type Traits = Pick<+ TextInputProps,+ 'enterKeyHint' | 'inputMode' | 'autoCapitalize'+>;++describe('keyboard-trait types', () => {+ it('are closed unions of the HTML-standard values', () => {+ expectTypeOf<EnterKeyHint>().toEqualTypeOf<+ 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'+ >();+ expectTypeOf<InputMode>().toEqualTypeOf<+ | 'none'+ | 'text'+ | 'tel'+ | 'url'+ | 'email'+ | 'numeric'+ | 'decimal'+ | 'search'+ >();+ expectTypeOf<AutoCapitalize>().toEqualTypeOf<+ 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'+ >();+ });++ it('type the props of every field that takes them', () => {+ expectTypeOf<+ NonNullable<TextInputProps['enterKeyHint']>+ >().toEqualTypeOf<EnterKeyHint>();+ expectTypeOf<+ NonNullable<TextInputProps['inputMode']>+ >().toEqualTypeOf<InputMode>();+ expectTypeOf<+ NonNullable<TextInputProps['autoCapitalize']>+ >().toEqualTypeOf<AutoCapitalize>();+ expectTypeOf<+ NonNullable<TextAreaProps['enterKeyHint']>+ >().toEqualTypeOf<EnterKeyHint>();+ expectTypeOf<+ NonNullable<TextAreaProps['inputMode']>+ >().toEqualTypeOf<InputMode>();+ expectTypeOf<+ NonNullable<TextAreaProps['autoCapitalize']>+ >().toEqualTypeOf<AutoCapitalize>();+ });++ it('reject a string outside the standard values', () => {+ const traits: Traits = {+ // @ts-expect-error -- not a Return key the HTML standard defines+ enterKeyHint: 'submit',+ // @ts-expect-error -- not a keyboard the HTML standard defines+ inputMode: 'number',+ // @ts-expect-error -- not a capitalization the HTML standard defines+ autoCapitalize: 'title',+ };+ expectTypeOf(traits).toEqualTypeOf<Traits>();+ });++ it('reject a string that has not been narrowed to the union', () => {+ const fromServer: string = 'send';+ // @ts-expect-error -- a plain string must be narrowed first+ const enterKeyHint: EnterKeyHint = fromServer;+ // @ts-expect-error -- a plain string must be narrowed first+ const inputMode: InputMode = fromServer;+ // @ts-expect-error -- a plain string must be narrowed first+ const autoCapitalize: AutoCapitalize = fromServer;+ expectTypeOf({enterKeyHint, inputMode, autoCapitalize}).toEqualTypeOf<{+ enterKeyHint: EnterKeyHint;+ inputMode: InputMode;+ autoCapitalize: AutoCapitalize;+ }>();+ });+});diff --git a/packages/core/src/Field/textEntryTraits.test.ts b/packages/core/src/Field/textEntryTraits.test.tsnew file mode 100644index 0000000000..334340b539--- /dev/null+++ b/packages/core/src/Field/textEntryTraits.test.ts@@ -0,0 +1,58 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file textEntryTraits.test.ts+ * @input textEntryTraitAttributes+ * @output Tests the mapping from keyboard-trait props to native attributes+ * @position Unit tests for Field/textEntryTraits.ts+ */++import {describe, expect, it} from 'vitest';+import {textEntryTraitAttributes} from './textEntryTraits';++describe('textEntryTraitAttributes', () => {+ it('renders nothing for absent traits', () => {+ expect(textEntryTraitAttributes({})).toEqual({});+ });++ it('passes the string traits through unchanged', () => {+ expect(+ textEntryTraitAttributes({+ enterKeyHint: 'previous',+ inputMode: 'none',+ autoCapitalize: 'characters',+ }),+ ).toEqual({+ enterKeyHint: 'previous',+ inputMode: 'none',+ autoCapitalize: 'characters',+ });+ });++ it.each(['off', 'on'] as const)(+ 'passes the HTML standard\u2019s other capitalization spelling %s through',+ autoCapitalize => {+ expect(textEntryTraitAttributes({autoCapitalize})).toEqual({+ autoCapitalize,+ });+ },+ );++ it('maps hasAutoCorrect onto the on/off keyword', () => {+ expect(textEntryTraitAttributes({hasAutoCorrect: true})).toEqual({+ autoCorrect: 'on',+ });+ expect(textEntryTraitAttributes({hasAutoCorrect: false})).toEqual({+ autoCorrect: 'off',+ });+ });++ it('omits a trait explicitly set to undefined', () => {+ expect(+ textEntryTraitAttributes({+ enterKeyHint: undefined,+ hasAutoCorrect: undefined,+ }),+ ).toEqual({});+ });+});diff --git a/packages/core/src/Field/textEntryTraits.ts b/packages/core/src/Field/textEntryTraits.tsnew file mode 100644index 0000000000..3855c77bc0--- /dev/null+++ b/packages/core/src/Field/textEntryTraits.ts@@ -0,0 +1,116 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file textEntryTraits.ts+ * @input The keyboard-trait props a text field accepts+ * @output Exports the closed value unions EnterKeyHint, InputMode and+ * AutoCapitalize (the package entry exports these three), the fields' prop+ * mixin TextEntryTraitProps, and textEntryTraitAttributes, which maps the+ * props onto the native attributes of the editable element+ * @position Shared by TextInput and TextArea: the one place that says how a+ * field tells a touch keyboard what it holds+ *+ * SYNC: When modified, update:+ * - /packages/core/src/TextInput/TextInput.tsx and TextInput.doc.mjs+ * - /packages/core/src/TextArea/TextArea.tsx and TextArea.doc.mjs+ * - /packages/core/src/Field/index.ts (type exports)+ */++/**+ * What the Return key of a touch keyboard says. iOS gives `done`, `go`,+ * `next`, `search` and `send` their own key (a glyph on iOS 26: a checkmark,+ * an arrow, a chevron, a magnifier, an up arrow); `enter` and `previous` keep+ * the plain Return key. Chrome on Android (Gboard) gives every value its own+ * key; with no hint, a single-line field's key reads Next while another field+ * follows and a multi-line field's keeps Return, and a `type="url"` field+ * shows Next instead of `go` while another field follows.+ */+export type EnterKeyHint =+ 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';++/**+ * Which touch keyboard a field asks for, by the HTML standard's `inputmode`+ * values. `numeric` brings up the number pad, and on iOS `search` brings up+ * the web-search keyboard (a period key and a Go key, whatever+ * `enterKeyHint` says).+ */+export type InputMode =+ 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search';++/**+ * When a touch keyboard capitalizes as you type: `off` and `none` never,+ * `on` and `sentences` at the start of each sentence (the HTML standard names+ * each of these two states twice), `words` at the start of each word, and+ * `characters` every letter.+ */+export type AutoCapitalize =+ 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters';++/**+ * Keyboard traits of a text field: a prop mixin for TextInput and TextArea,+ * not a component's props. A touch keyboard reads these traits from the+ * focused element. An absent prop renders no attribute, so the browser keeps+ * its own default (on iOS a field capitalizes sentences, except a URL field).+ */+export interface TextEntryTraitProps {+ /**+ * What the Return key of a touch keyboard says (the native `enterkeyhint`).+ * It only labels the key: what Enter does stays with the field's own+ * handlers.+ */+ enterKeyHint?: EnterKeyHint;+ /**+ * Which touch keyboard the field asks for (the native `inputmode`),+ * without changing what the field accepts.+ */+ inputMode?: InputMode;+ /**+ * When a touch keyboard capitalizes as you type (the native+ * `autocapitalize`).+ */+ autoCapitalize?: AutoCapitalize;+ /**+ * Whether a touch keyboard corrects words as you type (the native+ * `autocorrect`).+ */+ hasAutoCorrect?: boolean;+}++/** The native attributes the traits render as. */+export interface TextEntryTraitAttributes {+ enterKeyHint?: EnterKeyHint;+ inputMode?: InputMode;+ autoCapitalize?: AutoCapitalize;+ autoCorrect?: 'on' | 'off';+}++/**+ * Maps keyboard-trait props onto the native attributes for the editable+ * element. Absent props produce no attribute.+ *+ * @example+ * ```+ * <input {...textEntryTraitAttributes({enterKeyHint: 'search', hasAutoCorrect: false})} />+ * ```+ */+export function textEntryTraitAttributes({+ enterKeyHint,+ inputMode,+ autoCapitalize,+ hasAutoCorrect,+}: TextEntryTraitProps): TextEntryTraitAttributes {+ const attributes: TextEntryTraitAttributes = {};+ if (enterKeyHint != null) {+ attributes.enterKeyHint = enterKeyHint;+ }+ if (inputMode != null) {+ attributes.inputMode = inputMode;+ }+ if (autoCapitalize != null) {+ attributes.autoCapitalize = autoCapitalize;+ }+ if (hasAutoCorrect != null) {+ attributes.autoCorrect = hasAutoCorrect ? 'on' : 'off';+ }+ return attributes;+}diff --git a/packages/core/src/TextArea/TextArea.doc.mjs b/packages/core/src/TextArea/TextArea.doc.mjsindex e88b40a8cc..51f5135c6e 100644--- a/packages/core/src/TextArea/TextArea.doc.mjs+++ b/packages/core/src/TextArea/TextArea.doc.mjs@@ -212,7 +212,8 @@ export const docs = {{name: 'hasSpellCheck',type: 'boolean',- description: 'Enables or disables browser spell checking.',+ description:+ 'Enables or disables browser spell checking.',default: 'true',},{@@ -261,6 +262,30 @@ export const docs = {description:'The native autocomplete attribute, forwarded to the textarea unchanged. Does not affect the controlled value.',},+ {+ name: 'enterKeyHint',+ type: "'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'",+ description:+ 'What the Return key of a touch keyboard says (the native `enterkeyhint`). iOS gives `done`, `go`, `next`, `search` and `send` their own key (a glyph on iOS 26: a checkmark, an arrow, a chevron, a magnifier, an up arrow); `enter` and `previous` keep the plain Return key. Chrome on Android (Gboard) gives every value its own key; with no hint a TextArea keeps Return. It only labels the key: what Enter does stays with your handlers.',+ },+ {+ name: 'inputMode',+ type: "'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'",+ description:+ 'Which touch keyboard the field asks for (the native `inputmode`) without changing what it accepts: `numeric` brings up the number pad, `decimal` the decimal pad, `tel` the phone pad, `search` the web-search keyboard (whose Return key reads Go on iOS even with `enterKeyHint="search"`).',+ },+ {+ name: 'autoCapitalize',+ type: "'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'",+ description:+ 'When a touch keyboard capitalizes as you type (the native `autocapitalize`). Unset, iOS capitalizes sentences. `off` and `none` never capitalize; `on` and `sentences` capitalize each sentence.',+ },+ {+ name: 'hasAutoCorrect',+ type: 'boolean',+ description:+ 'Whether a touch keyboard corrects words as you type (the native `autocorrect`). Unset, the browser decides; turn it off for usernames, codes and other values that are not words.',+ },{name: 'containerXstyle',type: 'StyleXStyles',@@ -336,6 +361,11 @@ export const docs = {description:'Set maxLength with a character counter when there is a defined limit; it helps users stay within bounds before they submit.',},+ {+ guidance: true,+ description:+ 'Keep Return a line break in a multi-line field. Relabel it with enterKeyHint (send, done) only when your own Enter handling does what the label says.',+ },{guidance: true,description:@@ -535,6 +565,30 @@ export const docsZh = {type: 'string',description: '原生 autocomplete 属性,原样转发给文本域。不影响受控的值。',},+ {+ name: 'enterKeyHint',+ type: "'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'",+ description:+ '触屏键盘回车键上显示的内容(原生 `enterkeyhint`)。iOS 为 `done`、`go`、`next`、`search` 和 `send` 显示各自的按键(iOS 26 上为图标:对勾、箭头、右尖括号、放大镜、上箭头);`enter` 和 `previous` 保留普通的回车键。Android 上的 Chrome(Gboard)为每个值显示各自的按键;未设置时 TextArea 保留回车键。它只改变按键的标签:按下回车做什么仍由你的处理函数决定。',+ },+ {+ name: 'inputMode',+ type: "'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'",+ description:+ '字段请求的触屏键盘(原生 `inputmode`),不改变字段接受的内容:`numeric` 显示数字键盘,`decimal` 显示带小数点的数字键盘,`tel` 显示电话键盘,`search` 显示网页搜索键盘(即使设置了 `enterKeyHint="search"`,iOS 上它的回车键仍显示为“前往”)。',+ },+ {+ name: 'autoCapitalize',+ type: "'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'",+ description:+ '触屏键盘在输入时何时自动大写(原生 `autocapitalize`)。未设置时,iOS 会将句首大写。`off` 与 `none` 从不大写;`on` 与 `sentences` 将每句句首大写。',+ },+ {+ name: 'hasAutoCorrect',+ type: 'boolean',+ description:+ '触屏键盘是否在输入时自动更正单词(原生 `autocorrect`)。未设置时由浏览器决定;对用户名、验证码等不是单词的值请关闭它。',+ },{name: 'containerXstyle',type: 'StyleXStyles',@@ -609,6 +663,11 @@ export const docsZh = {description:'Set maxLength with a character counter when there is a defined limit; it helps users stay within bounds before they submit.',},+ {+ guidance: true,+ description:+ 'Keep Return a line break in a multi-line field. Relabel it with enterKeyHint (send, done) only when your own Enter handling does what the label says.',+ },{guidance: true,description:@@ -659,6 +718,11 @@ export const docsDense = {guidance: true,description: 'Set maxLength for character counter when a limit exists.',},+ {+ guidance: true,+ description:+ 'Return stays a line break; relabel it (enterKeyHint) only if your Enter handling matches.',+ },{guidance: true,description:diff --git a/packages/core/src/TextArea/TextArea.test.tsx b/packages/core/src/TextArea/TextArea.test.tsxindex f696e3aae6..bffb723345 100644--- a/packages/core/src/TextArea/TextArea.test.tsx+++ b/packages/core/src/TextArea/TextArea.test.tsx@@ -1022,6 +1022,57 @@ describe('TextArea', () => {});});+ describe('touch keyboard traits', () => {+ it('renders no trait attribute when none is set, leaving the browser default', () => {+ render(<TextArea label="Notes" value="" onChange={() => {}} />);+ const textarea = screen.getByRole('textbox');+ for (const attribute of [+ 'enterkeyhint',+ 'inputmode',+ 'autocapitalize',+ 'autocorrect',+ ]) {+ expect(textarea).not.toHaveAttribute(attribute);+ }+ });++ it('forwards every trait to the native textarea', () => {+ render(+ <TextArea+ label="Message"+ value=""+ onChange={() => {}}+ enterKeyHint="send"+ inputMode="text"+ autoCapitalize="sentences"+ hasAutoCorrect={false}+ hasSpellCheck={false}+ />,+ );+ const textarea = screen.getByRole('textbox');+ expect(textarea).toHaveAttribute('enterkeyhint', 'send');+ expect(textarea).toHaveAttribute('inputmode', 'text');+ expect(textarea).toHaveAttribute('autocapitalize', 'sentences');+ expect(textarea).toHaveAttribute('autocorrect', 'off');+ expect(textarea).toHaveAttribute('spellcheck', 'false');+ });++ it('keeps Return a line break whatever enterKeyHint says', async () => {+ const user = userEvent.setup();+ const onChange = vi.fn();+ render(+ <TextArea+ label="Message"+ value="a"+ onChange={onChange}+ enterKeyHint="send"+ />,+ );+ await user.type(screen.getByRole('textbox'), '{Enter}');+ expect(onChange).toHaveBeenLastCalledWith('a\n', expect.anything());+ });+ });+describe('autoComplete prop (#5638)', () => {it('forwards autoComplete to the native textarea unchanged', () => {render(diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsxindex 09bcac7f18..9776d72b5d 100644--- a/packages/core/src/TextArea/TextArea.tsx+++ b/packages/core/src/TextArea/TextArea.tsx@@ -4,7 +4,8 @@/*** @file TextArea.tsx- * @input Uses React, useId, ChangeEvent, ClipboardEvent, FocusEvent, Field, Icon, Spinner+ * @input Uses React, useId, ChangeEvent, ClipboardEvent, FocusEvent, Field, Icon, Spinner,+ * textEntryTraits (the touch-keyboard trait props)* @output Exports TextArea component, TextAreaProps, TextAreaStatus, TextAreaStatusType* @position Core implementation; consumed by index.ts, tested by TextArea.test.tsx*@@ -62,6 +63,10 @@ import {useResolvedRequired} from '../hooks/useResolvedRequired';import {useSize} from '../SizeContext/SizeContext';import {themeProps} from '../utils/themeProps';import {characterCount} from '../utils/characters';+import {+ textEntryTraitAttributes,+ type TextEntryTraitProps,+} from '../Field/textEntryTraits';import {useMergedRefs} from '../hooks/useMergedRefs';import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';@@ -208,10 +213,10 @@ export interface TextAreaStatus {message?: string;}-export interface TextAreaProps extends Omit<- FieldInputBaseProps,- 'onChange' | 'defaultValue'-> {+export interface TextAreaProps+ extends+ Omit<FieldInputBaseProps, 'onChange' | 'defaultValue'>,+ TextEntryTraitProps {/** Ref forwarded to the root element */ref?: React.Ref<HTMLTextAreaElement>;/**@@ -408,6 +413,10 @@ export function TextArea({labelTooltip,startIcon,hasSpellCheck = true,+ enterKeyHint,+ inputMode,+ autoCapitalize,+ hasAutoCorrect,onPaste,maxLength,hasAutoFocus = false,@@ -650,6 +659,12 @@ export function TextArea({onBlur={onBlur}placeholder={placeholder}rows={rows}+ {...textEntryTraitAttributes({+ enterKeyHint,+ inputMode,+ autoCapitalize,+ hasAutoCorrect,+ })}// A disabled textarea keeps its place in the tab order// (spec:AST-085): aria-disabled instead of the native attribute,// with readOnly + the handleChange guard keeping the value fromdiff --git a/packages/core/src/TextArea/__tests__/TextAreaKeyboardTraits.a11y.chromium.spec.ts b/packages/core/src/TextArea/__tests__/TextAreaKeyboardTraits.a11y.chromium.spec.tsnew file mode 100644index 0000000000..f5ee9818f8--- /dev/null+++ b/packages/core/src/TextArea/__tests__/TextAreaKeyboardTraits.a11y.chromium.spec.ts@@ -0,0 +1,90 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @pr-a11y scope ^(packages/core/src/TextArea/|packages/core/src/Field/textEntryTraits|apps/storybook/stories/TextArea)++/**+ * @file TextAreaKeyboardTraits.a11y.chromium.spec.ts+ * @input The `Core/TextArea` KeyboardTraits story in a built Storybook, in+ * Chromium on a phone viewport with touch emulation.+ * @output Real-browser proof of component:TextArea FR13: a textarea a finger+ * focuses carries the touch-keyboard attributes its props set and none its+ * props leave unset.+ * @position Runs in pr-a11y when TextArea, its keyboard traits or its stories+ * change. jsdom has no touch input, so only a browser shows what the+ * textarea a tap focuses carries when the keyboard opens.+ */++import {expect, test, type Locator} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;+test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});+test.afterAll(async () => {+ await storybook?.close();+});++test.use({hasTouch: true, viewport: {width: 390, height: 844}});++const ATTRIBUTES = [+ 'enterkeyhint',+ 'inputmode',+ 'autocapitalize',+ 'autocorrect',+] as const;++type Attributes = Record<(typeof ATTRIBUTES)[number], string | null>;++/** Taps the field, then reads the touch-keyboard attributes of the focused textarea. */+async function tapAndRead(field: Locator): Promise<Attributes> {+ await field.tap();+ await expect(field).toBeFocused();+ return field.evaluate(+ (textarea, names) => {+ const read: Record<string, string | null> = {};+ for (const name of names) {+ read[name] = textarea.getAttribute(name);+ }+ return read;+ },+ ATTRIBUTES as unknown as string[],+ ) as Promise<Attributes>;+}++test('the textarea a tap focuses carries exactly the keyboard attributes its props set', async ({+ page,+}) => {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-textarea--keyboard-traits&viewMode=story`,+ );+ // Present and painted before anything is judged.+ const command = page.getByRole('textbox', {name: 'Shell command'});+ const caption = page.getByRole('textbox', {name: 'Photo caption'});+ for (const field of [command, caption]) {+ await expect(field).toBeVisible();+ const box = await field.boundingBox();+ expect(box?.width ?? 0).toBeGreaterThan(0);+ expect(box?.height ?? 0).toBeGreaterThan(0);+ }++ // A shell command is typed exactly: no capitalization or correction.+ expect(await tapAndRead(command)).toEqual({+ enterkeyhint: null,+ inputmode: null,+ autocapitalize: 'none',+ autocorrect: 'off',+ });+ // A caption capitalizes each word and leaves the rest to the browser.+ expect(await tapAndRead(caption)).toEqual({+ enterkeyhint: null,+ inputmode: null,+ autocapitalize: 'words',+ autocorrect: null,+ });+});diff --git a/packages/core/src/TextInput/TextInput.doc.mjs b/packages/core/src/TextInput/TextInput.doc.mjsindex 4ed255df89..0589218c96 100644--- a/packages/core/src/TextInput/TextInput.doc.mjs+++ b/packages/core/src/TextInput/TextInput.doc.mjs@@ -10,9 +10,9 @@ export const docs = {props: [{name: 'type',- type: "'text' | 'password' | 'email'",+ type: "'text' | 'password' | 'email' | 'search' | 'tel' | 'url'",description:- 'The HTML input type.',+ 'The HTML input type. `email`, `tel` and `url` also bring up the matching touch keyboard (email, phone pad, URL); `search` makes the field a search box (pair it with `enterKeyHint="search"` for a Search key on iOS; Chrome on Android shows one for `type="search"` alone).',default: "'text'",},{@@ -168,7 +168,37 @@ export const docs = {name: 'autoComplete',type: 'string',description:- 'The native autocomplete attribute, forwarded to the input unchanged. Does not affect the controlled value.',+ 'The native autocomplete attribute, forwarded to the input unchanged. Does not affect the controlled value. It is also how AutoFill knows what a field holds: tag sign-in, address and payment fields (`username`, `new-password`, `one-time-code`, `email`, `tel`, `street-address`, …).',+ },+ {+ name: 'enterKeyHint',+ type: "'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'",+ description:+ 'What the Return key of a touch keyboard says (the native `enterkeyhint`). iOS gives `done`, `go`, `next`, `search` and `send` their own key (a glyph on iOS 26: a checkmark, an arrow, a chevron, a magnifier, an up arrow); `enter` and `previous` keep the plain Return key. Chrome on Android (Gboard) gives every value its own key, `enter` and `previous` included; with no hint the key reads Next while another field follows, and a `type="url"` field shows Next instead of `go` while another field follows. It only labels the key: what Enter does stays with your handlers.',+ },+ {+ name: 'inputMode',+ type: "'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'",+ description:+ 'Which touch keyboard the field asks for (the native `inputmode`) without changing what it accepts: `numeric` brings up the number pad, `decimal` the decimal pad, `tel` the phone pad, `search` the web-search keyboard (whose Return key reads Go on iOS even with `enterKeyHint="search"`; Chrome on Android shows the Enter key for `inputMode="search"` alone).',+ },+ {+ name: 'autoCapitalize',+ type: "'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'",+ description:+ 'When a touch keyboard capitalizes as you type (the native `autocapitalize`). Unset, iOS capitalizes sentences, except in a URL field. `off` and `none` never capitalize; `on` and `sentences` capitalize each sentence.',+ },+ {+ name: 'hasAutoCorrect',+ type: 'boolean',+ description:+ 'Whether a touch keyboard corrects words as you type (the native `autocorrect`). Unset, the browser decides; turn it off for usernames, codes and other values that are not words.',+ },+ {+ name: 'hasSpellCheck',+ type: 'boolean',+ description:+ 'Whether misspelled words are underlined (the native `spellcheck`). Unset, the browser decides.',},{name: 'containerXstyle',@@ -216,6 +246,7 @@ export const docs = {{guidance: true, description: 'Use validation status with a message to explain what went wrong: "Email must include @" is better than just turning the border red.'},{guidance: true, description: 'Size the input to match the expected content length so users can gauge how much to type: small for zip codes, medium for names, large for URLs.'},{guidance: true, description: 'Add a clear button for search and filter inputs so users can quickly reset without selecting all text.'},+ {guidance: true, description: 'Tell a touch keyboard what the field holds: `type="email"`, `"tel"` or `"url"` for those values, `inputMode="numeric"` for digits that are not a number (a one-time code), `enterKeyHint` for what Return does (Search, Send, Next), and `autoComplete` so AutoFill can fill it.'},{guidance: false, description: "Don't use placeholder text as a replacement for a label; placeholders disappear on focus and are not reliably read by screen readers."},{guidance: false, description: "Don't use TextInput for multi-line content like comments or descriptions; use TextArea instead."},{guidance: false, description: "Don't mark every field as required; only flag mandatory fields so users are not overwhelmed by validation errors."},@@ -240,8 +271,9 @@ export const docsZh = {props: [{name: 'type',- type: "'text' | 'password' | 'email'",- description: 'HTML 输入框类型。',+ type: "'text' | 'password' | 'email' | 'search' | 'tel' | 'url'",+ description:+ 'HTML 输入框类型。`email`、`tel` 和 `url` 还会调出对应的触屏键盘(邮箱、电话键盘、URL);`search` 让字段成为搜索框(在 iOS 上配合 `enterKeyHint="search"` 显示搜索键;Android 上的 Chrome 单独设置 `type="search"` 即显示搜索键)。',default: "'text'",},{@@ -379,7 +411,37 @@ export const docsZh = {name: 'autoComplete',type: 'string',description:- '原生 autocomplete 属性,原样转发给输入框。不影响受控的值。',+ '原生 autocomplete 属性,原样转发给输入框。不影响受控的值。自动填充也靠它判断字段的内容:请为登录、地址和支付字段设置对应的值(`username`、`new-password`、`one-time-code`、`email`、`tel`、`street-address` 等)。',+ },+ {+ name: 'enterKeyHint',+ type: "'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'",+ description:+ '触屏键盘回车键上显示的内容(原生 `enterkeyhint`)。iOS 为 `done`、`go`、`next`、`search` 和 `send` 显示各自的按键(iOS 26 上为图标:对勾、箭头、右尖括号、放大镜、上箭头);`enter` 和 `previous` 保留普通的回车键。Android 上的 Chrome(Gboard)为每个值显示各自的按键,包括 `enter` 和 `previous`;未设置时,后面还有字段则显示“下一项”;`type="url"` 的字段后面还有字段时,即使设为 `go` 也显示“下一项”。它只改变按键的标签:按下回车做什么仍由你的处理函数决定。',+ },+ {+ name: 'inputMode',+ type: "'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'",+ description:+ '字段请求的触屏键盘(原生 `inputmode`),不改变字段接受的内容:`numeric` 显示数字键盘,`decimal` 显示带小数点的数字键盘,`tel` 显示电话键盘,`search` 显示网页搜索键盘(即使设置了 `enterKeyHint="search"`,iOS 上它的回车键仍显示为“前往”;Android 上的 Chrome 对单独的 `inputMode="search"` 显示回车键)。',+ },+ {+ name: 'autoCapitalize',+ type: "'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'",+ description:+ '触屏键盘在输入时何时自动大写(原生 `autocapitalize`)。未设置时,iOS 会将句首大写,但 URL 字段除外。`off` 与 `none` 从不大写;`on` 与 `sentences` 将每句句首大写。',+ },+ {+ name: 'hasAutoCorrect',+ type: 'boolean',+ description:+ '触屏键盘是否在输入时自动更正单词(原生 `autocorrect`)。未设置时由浏览器决定;对用户名、验证码等不是单词的值请关闭它。',+ },+ {+ name: 'hasSpellCheck',+ type: 'boolean',+ description:+ '是否为拼错的单词加下划线(原生 `spellcheck`)。未设置时由浏览器决定。',},{name: 'containerXstyle',@@ -427,6 +489,7 @@ export const docsZh = {{guidance: true, description: 'Use validation status with a message to explain what went wrong: "Email must include @" is better than just turning the border red.'},{guidance: true, description: 'Size the input to match the expected content length so users can gauge how much to type: small for zip codes, medium for names, large for URLs.'},{guidance: true, description: 'Add a clear button for search and filter inputs so users can quickly reset without selecting all text.'},+ {guidance: true, description: 'Tell a touch keyboard what the field holds: `type="email"`, `"tel"` or `"url"` for those values, `inputMode="numeric"` for digits that are not a number (a one-time code), `enterKeyHint` for what Return does (Search, Send, Next), and `autoComplete` so AutoFill can fill it.'},{guidance: false, description: "Don't use placeholder text as a replacement for a label; placeholders disappear on focus and are not reliably read by screen readers."},{guidance: false, description: "Don't use TextInput for multi-line content like comments or descriptions; use TextArea instead."},{guidance: false, description: "Don't mark every field as required; only flag mandatory fields so users are not overwhelmed by validation errors."},@@ -455,6 +518,7 @@ export const docsDense = {{guidance: true, description: 'Use validation status with a message to explain what went wrong: "Email must include @" is better than just turning the border red.'},{guidance: true, description: 'Size the input to match the expected content length so users can gauge how much to type: small for zip codes, medium for names, large for URLs.'},{guidance: true, description: 'Add a clear button for search and filter inputs so users can quickly reset without selecting all text.'},+ {guidance: true, description: 'Tell a touch keyboard what the field holds: `type="email"`, `"tel"` or `"url"` for those values, `inputMode="numeric"` for digits that are not a number (a one-time code), `enterKeyHint` for what Return does (Search, Send, Next), and `autoComplete` so AutoFill can fill it.'},{guidance: false, description: "Don't use placeholder text as a replacement for a label; placeholders disappear on focus and are not reliably read by screen readers."},{guidance: false, description: "Don't use TextInput for multi-line content like comments or descriptions; use TextArea instead."},{guidance: false, description: "Don't mark every field as required; only flag mandatory fields so users are not overwhelmed by validation errors."},diff --git a/packages/core/src/TextInput/TextInput.test.tsx b/packages/core/src/TextInput/TextInput.test.tsxindex ea0a66fe4d..8823d89b3d 100644--- a/packages/core/src/TextInput/TextInput.test.tsx+++ b/packages/core/src/TextInput/TextInput.test.tsx@@ -668,6 +668,198 @@ describe('TextInput', () => {});});+ describe('touch keyboard traits', () => {+ it('renders no trait attribute when none is set, leaving the browser default', () => {+ render(<TextInput label="Name" value="" onChange={() => {}} />);+ const input = screen.getByRole('textbox');+ for (const attribute of [+ 'enterkeyhint',+ 'inputmode',+ 'autocapitalize',+ 'autocorrect',+ 'spellcheck',+ ]) {+ expect(input).not.toHaveAttribute(attribute);+ }+ });++ it('labels the Return key with enterKeyHint', () => {+ render(+ <TextInput+ label="Search"+ value=""+ onChange={() => {}}+ enterKeyHint="search"+ />,+ );+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'enterkeyhint',+ 'search',+ );+ });++ it.each([+ 'enter',+ 'done',+ 'go',+ 'next',+ 'previous',+ 'search',+ 'send',+ ] as const)(+ 'calls onEnter on Enter whatever the Return key says (%s)',+ async enterKeyHint => {+ const user = userEvent.setup();+ const onEnter = vi.fn();+ render(+ <TextInput+ label="Field"+ value=""+ onChange={() => {}}+ enterKeyHint={enterKeyHint}+ onEnter={onEnter}+ />,+ );+ await user.type(screen.getByRole('textbox'), '{Enter}');+ expect(onEnter).toHaveBeenCalledTimes(1);+ },+ );++ it('asks for a keyboard with inputMode without changing the type', () => {+ render(+ <TextInput+ label="Amount"+ value=""+ onChange={() => {}}+ inputMode="decimal"+ />,+ );+ const input = screen.getByRole('textbox');+ expect(input).toHaveAttribute('inputmode', 'decimal');+ expect(input).toHaveAttribute('type', 'text');+ });++ it('sets capitalization, correction and spell checking', () => {+ render(+ <TextInput+ label="Username"+ value=""+ onChange={() => {}}+ autoCapitalize="none"+ hasAutoCorrect={false}+ hasSpellCheck={false}+ />,+ );+ const input = screen.getByRole('textbox');+ expect(input).toHaveAttribute('autocapitalize', 'none');+ expect(input).toHaveAttribute('autocorrect', 'off');+ expect(input).toHaveAttribute('spellcheck', 'false');+ });++ it('keeps an untyped spellCheck passed through while hasSpellCheck is unset', () => {+ const passthrough = {spellCheck: false} as Record<string, unknown>;+ render(+ <TextInput+ label="Code"+ value=""+ onChange={() => {}}+ {...passthrough}+ />,+ );+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'spellcheck',+ 'false',+ );+ });++ it('turns correction and spell checking on explicitly', () => {+ render(+ <TextInput+ label="Title"+ value=""+ onChange={() => {}}+ autoCapitalize="words"+ hasAutoCorrect+ hasSpellCheck+ />,+ );+ const input = screen.getByRole('textbox');+ expect(input).toHaveAttribute('autocapitalize', 'words');+ expect(input).toHaveAttribute('autocorrect', 'on');+ expect(input).toHaveAttribute('spellcheck', 'true');+ });++ it('keeps the traits on the input inside an InputGroup', () => {+ render(+ <InputGroup label="Website">+ <TextInput+ label="Website"+ value=""+ onChange={() => {}}+ type="url"+ enterKeyHint="go"+ autoCapitalize="none"+ />+ </InputGroup>,+ );+ const input = screen.getByRole('textbox');+ expect(input).toHaveAttribute('type', 'url');+ expect(input).toHaveAttribute('enterkeyhint', 'go');+ expect(input).toHaveAttribute('autocapitalize', 'none');+ });++ it('lets the trait props win over the same attributes passed untyped', () => {+ const untyped = {enterKeyHint: 'done', autoCorrect: 'on'} as object;+ render(+ <TextInput+ label="Code"+ value=""+ onChange={() => {}}+ {...untyped}+ enterKeyHint="next"+ hasAutoCorrect={false}+ />,+ );+ const input = screen.getByRole('textbox');+ expect(input).toHaveAttribute('enterkeyhint', 'next');+ expect(input).toHaveAttribute('autocorrect', 'off');+ });+ });++ describe('type', () => {+ it.each([+ ['search', 'searchbox'],+ ['tel', 'textbox'],+ ['url', 'textbox'],+ ['email', 'textbox'],+ ] as const)('renders type="%s" as a %s', (type, role) => {+ render(+ <TextInput label="Field" value="" onChange={() => {}} type={type} />,+ );+ expect(screen.getByRole(role, {name: 'Field'})).toHaveAttribute(+ 'type',+ type,+ );+ });++ it('keeps onEnter on a search field', async () => {+ const user = userEvent.setup();+ const onEnter = vi.fn();+ render(+ <TextInput+ label="Search"+ value=""+ onChange={() => {}}+ type="search"+ enterKeyHint="search"+ onEnter={onEnter}+ />,+ );+ await user.type(screen.getByRole('searchbox'), '{Enter}');+ expect(onEnter).toHaveBeenCalledTimes(1);+ });+ });+describe('onEnter', () => {it('calls onEnter when Enter key is pressed', async () => {const user = userEvent.setup();diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsxindex 7658363724..f76973b079 100644--- a/packages/core/src/TextInput/TextInput.tsx+++ b/packages/core/src/TextInput/TextInput.tsx@@ -4,8 +4,9 @@/*** @file TextInput.tsx- * @input Uses React, useId, ChangeEvent, Field, Icon, InputGroupContext- * @output Exports TextInput component, TextInputProps+ * @input Uses React, useId, ChangeEvent, Field, Icon, InputGroupContext,+ * textEntryTraits (the touch-keyboard trait props)+ * @output Exports TextInput component, TextInputProps, TextInputType* @position Core implementation; consumed by index.ts, tested by TextInput.test.tsx** SYNC: When modified, update these files to stay in sync:@@ -49,6 +50,10 @@ import {Spinner} from '../Spinner';import {useTooltip} from '../Tooltip';import {VisuallyHidden} from '../VisuallyHidden';import {getInputARIA, isImeKeyEvent} from '../utils';+import {+ textEntryTraitAttributes,+ type TextEntryTraitProps,+} from '../Field/textEntryTraits';import {joinAriaIDs} from '../utils/inputAria';const styles = stylex.create({@@ -130,16 +135,24 @@ import {import english from '../i18n/generated-english/TextInput/TextInput.generated';registerEnglishFallback(english);-export type TextInputType = 'text' | 'password' | 'email';+/**+ * The HTML input type. Beyond their meaning, `email`, `tel`, `url` and+ * `password` choose a touch keyboard (email, phone pad, URL) and its+ * capitalization; `search` makes the field a search box.+ */+export type TextInputType =+ 'text' | 'password' | 'email' | 'search' | 'tel' | 'url';-export interface TextInputProps extends Omit<- FieldInputBaseProps,- 'onChange' | 'defaultValue'-> {+export interface TextInputProps+ extends+ Omit<FieldInputBaseProps, 'onChange' | 'defaultValue'>,+ TextEntryTraitProps {/** Ref forwarded to the root element */ref?: React.Ref<HTMLInputElement>;/**- * The HTML input type.+ * The HTML input type. `email`, `tel` and `url` also bring up the matching+ * touch keyboard (email, phone pad, URL); `search` makes the field a search+ * box (pair it with `enterKeyHint="search"` for a Search key).* @default 'text'*/type?: TextInputType;@@ -289,6 +302,11 @@ export interface TextInputProps extends Omit<* session-scoped field that must not reuse a prior value).*/autoComplete?: React.InputHTMLAttributes<HTMLInputElement>['autoComplete'];+ /**+ * Whether misspelled words are underlined (the native `spellcheck`).+ * Unset, the browser decides.+ */+ hasSpellCheck?: boolean;}/**@@ -325,6 +343,11 @@ export function TextInput({htmlName,onEnter,onKeyDown,+ enterKeyHint,+ inputMode,+ autoCapitalize,+ hasAutoCorrect,+ hasSpellCheck,width,containerXstyle,containerClassName,@@ -506,6 +529,14 @@ export function TextInput({id={id}name={isDisabled ? undefined : htmlName}type={type}+ {...textEntryTraitAttributes({+ enterKeyHint,+ inputMode,+ autoCapitalize,+ hasAutoCorrect,+ })}+ // Only when set, so an untyped `spellCheck` passed through still applies.+ {...(hasSpellCheck != null ? {spellCheck: hasSpellCheck} : {})}value={optimisticValue}onChange={handleChange}onKeyDown={diff --git a/packages/core/src/TextInput/__tests__/TextInputKeyboardTraits.a11y.chromium.spec.ts b/packages/core/src/TextInput/__tests__/TextInputKeyboardTraits.a11y.chromium.spec.tsnew file mode 100644index 0000000000..5e81210ce5--- /dev/null+++ b/packages/core/src/TextInput/__tests__/TextInputKeyboardTraits.a11y.chromium.spec.ts@@ -0,0 +1,126 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @pr-a11y scope ^(packages/core/src/TextInput/|packages/core/src/Field/textEntryTraits|apps/storybook/stories/TextInput)++/**+ * @file TextInputKeyboardTraits.a11y.chromium.spec.ts+ * @input The `Core/TextInput` KeyboardTraits story in a built Storybook, in+ * Chromium on a phone viewport with touch emulation.+ * @output Real-browser proof of component:TextInput FR16 and AR6: a field a+ * finger focuses carries the touch-keyboard attributes its props set and+ * none its props leave unset, and a search field is a searchbox.+ * @position Runs in pr-a11y when TextInput, its keyboard traits or its+ * stories change. jsdom has no touch input, so only a browser shows what the+ * input a tap focuses carries when the keyboard opens.+ */++import {expect, test, type Locator} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;+test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});+test.afterAll(async () => {+ await storybook?.close();+});++test.use({hasTouch: true, viewport: {width: 390, height: 844}});++const ATTRIBUTES = [+ 'type',+ 'enterkeyhint',+ 'inputmode',+ 'autocapitalize',+ 'autocorrect',+ 'spellcheck',+] as const;++type Attributes = Record<(typeof ATTRIBUTES)[number], string | null>;++/** Taps the field, then reads the touch-keyboard attributes of the focused input. */+async function tapAndRead(field: Locator): Promise<Attributes> {+ await field.tap();+ await expect(field).toBeFocused();+ return field.evaluate(+ (input, names) => {+ const read: Record<string, string | null> = {};+ for (const name of names) {+ read[name] = input.getAttribute(name);+ }+ return read;+ },+ ATTRIBUTES as unknown as string[],+ ) as Promise<Attributes>;+}++const NONE = {+ inputmode: null,+ autocapitalize: null,+ autocorrect: null,+ spellcheck: null,+};++test('the input a tap focuses carries exactly the keyboard attributes its props set', async ({+ page,+}) => {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-textinput--keyboard-traits&viewMode=story`,+ );+ // Present and painted before anything is judged: every field of the story+ // renders a visible input.+ const search = page.getByRole('searchbox', {name: 'Search'});+ const phone = page.getByRole('textbox', {name: 'Phone'});+ const website = page.getByRole('textbox', {name: 'Website'});+ const code = page.getByRole('textbox', {name: 'Verification code'});+ const username = page.getByRole('textbox', {name: 'Username'});+ for (const field of [search, phone, website, code, username]) {+ await expect(field).toBeVisible();+ const box = await field.boundingBox();+ expect(box?.width ?? 0).toBeGreaterThan(0);+ expect(box?.height ?? 0).toBeGreaterThan(0);+ }++ // A search field is a searchbox (AR6) whose keyboard says Search and+ // neither capitalizes nor corrects.+ expect(await tapAndRead(search)).toEqual({+ ...NONE,+ type: 'search',+ enterkeyhint: 'search',+ autocapitalize: 'none',+ autocorrect: 'off',+ });+ // The phone and URL types bring their own keyboards; only the Return key+ // label is set.+ expect(await tapAndRead(phone)).toEqual({+ ...NONE,+ type: 'tel',+ enterkeyhint: 'next',+ });+ expect(await tapAndRead(website)).toEqual({+ ...NONE,+ type: 'url',+ enterkeyhint: 'go',+ });+ // A one-time code asks for the number pad without changing the type.+ expect(await tapAndRead(code)).toEqual({+ ...NONE,+ type: 'text',+ enterkeyhint: 'done',+ inputmode: 'numeric',+ });+ // A username turns off capitalization, correction and spell checking.+ expect(await tapAndRead(username)).toEqual({+ type: 'text',+ enterkeyhint: 'next',+ inputmode: null,+ autocapitalize: 'none',+ autocorrect: 'off',+ spellcheck: 'false',+ });+});diff --git a/packages/native/src/components/TextInput.ts b/packages/native/src/components/TextInput.tsindex 9d996be7f6..7c7de130e8 100644--- a/packages/native/src/components/TextInput.ts+++ b/packages/native/src/components/TextInput.ts@@ -14,7 +14,20 @@ export const textInput: NativeAdditions = {name: 'TextInput',// family:input-fields routes base props to the primary semantic control.baseTarget: 'control',+ // The Swift field applies only these types; search, tel and url stay in+ // the web contract.+ projections: {type: {text: 'text', password: 'password', email: 'email'}},webOnly: {autoComplete: 'HTML autocomplete attribute',+ // Touch-keyboard props join a native contract only where that platform's+ // field applies them.+ enterKeyHint:+ 'touch-keyboard Return key label the Swift field does not apply',+ inputMode: 'touch keyboard choice the Swift field does not apply',+ autoCapitalize:+ 'touch-keyboard capitalization the Swift field does not apply',+ hasAutoCorrect:+ 'touch-keyboard autocorrection the Swift field does not apply',+ hasSpellCheck: 'spell-check marking the Swift field does not apply',},};