An open source design system that's fully customizable and agent ready
TypeScript
feat(ChatComposerInput): the touch keyboard's Return key says Send (#8167)
Christopher Chedeau65ad191d8ef1
diff --git a/.changeset/chat-composer-return-key-send.md b/.changeset/chat-composer-return-key-send.mdnew file mode 100644index 0000000000..c96ed56d47--- /dev/null+++ b/.changeset/chat-composer-return-key-send.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] ChatComposerInput's Return key says Send on a touch keyboard. Enter already sends the message; the editor now sets `enterkeyhint="send"`, so iOS shows its Send key instead of a plain Return. A new `enterKeyHint` prop, typed by the exported closed union `EnterKeyHint`, takes another label, such as `enter` for a composer whose `onKeyDown` makes Enter insert a line break on touch keyboards.++@vjeuxdiff --git a/apps/storybook/stories/ChatComposer.stories.tsx b/apps/storybook/stories/ChatComposer.stories.tsxindex ef63d2ff98..fc00025b0c 100644--- a/apps/storybook/stories/ChatComposer.stories.tsx+++ b/apps/storybook/stories/ChatComposer.stories.tsx@@ -108,7 +108,9 @@ export const Simplest: Story = {* soft-keyboard Return inserts a newline instead of sending (and never strands* a multi-line prompt); on a pointer device Enter sends as usual. The same* seam covers shortcuts like Cmd/Ctrl+Enter — just call submit yourself.- * IME composition is always respected regardless.+ * `enterKeyHint` keeps the touch keyboard's Return key honest: Send where+ * Enter sends, Return where it inserts a line break. IME composition is+ * always respected regardless.*/export const EnterBehavior: Story = {render: () => {@@ -125,6 +127,9 @@ export const EnterBehavior: Story = {? 'Enter inserts a newline on touch — use Send': 'Enter sends; Shift+Enter for a newline'}+ // The Return key says what Enter does: Send where Enter sends,+ // Return where it inserts a line break.+ enterKeyHint={isCoarsePointer ? 'enter' : 'send'}onKeyDown={e => {if (isCoarsePointer && e.key === 'Enter' && !e.shiftKey) {e.preventDefault();diff --git a/docs/specs/components/Chat/ChatComposerInput.spec.md b/docs/specs/components/Chat/ChatComposerInput.spec.mdindex 4c4e3f18b2..53d7b39699 100644--- a/docs/specs/components/Chat/ChatComposerInput.spec.md+++ b/docs/specs/components/Chat/ChatComposerInput.spec.md@@ -13,6 +13,8 @@ review_triggers: [public-api, behavior, accessibility, interaction, theming]verified_by:[packages/core/src/Chat/ChatComposerInput.test.tsx,+ packages/core/src/Chat/ChatComposerInput.public.test.ts,+ packages/core/src/Chat/__tests__/ChatComposerReturnKey.a11y.chromium.spec.ts,apps/storybook/stories/ChatComposerInput.stories.tsx,apps/storybook/rtl-audit/verified-not-applicable.json,]@@ -39,7 +41,7 @@ system_specs: [spec:AST-002, spec:AST-029]| Behavior | Every edit path keeps the serialized draft observable. Files pasted or dropped reach `onFiles`; consumer `onPaste` receives first refusal over plain text before optional paste-as-token conversion. || End-user impact | Dictated or otherwise programmatically inserted text is sendable and never hidden behind the empty placeholder; dropped files reach the product attachment flow. On a phone, the Return key says Send, which is what Enter does. || Builder impact | Existing props, callback signatures, exports, and token serialization are unchanged. Builders relying on the documented `onPaste` and `onFiles` paths receive those callbacks except where FR5 and FR6 record implementation gaps; `hasMultiWordQuery` is an added optional trigger field, and `enterKeyHint` an added optional prop whose `send` default a composer that makes Enter insert a line break replaces with `enter` (FR17). Every trigger receives the trigger-key corrections listed under Compatibility and migration (FR10, FR13, FR15, FR16). |-| Compatibility/readiness | Patch-compatible. One additive optional trigger field (DEC-1), one additive optional prop with a keyboard-hint default (DEC-2, a patch `[feat]` under `spec:AST-017` FR5, FR7), plus trigger-key corrections that apply to every trigger (FR10, FR13, FR15, FR16); no visual decision. Implementation gaps are recorded inline on FR1, FR5, FR6, FR10, FR17, and PR2. |+| Compatibility/readiness | Patch-compatible. One additive optional trigger field (DEC-1), one additive optional prop with a keyboard-hint default (DEC-2, a patch `[feat]` under `spec:AST-017` FR5, FR7), plus trigger-key corrections that apply to every trigger (FR10, FR13, FR15, FR16); no visual decision. Implementation gaps are recorded inline on FR1, FR5, FR6, FR10, and PR2. || Review checks | Reject an edit path that mutates the DOM without updating the serialized draft, a file drop that can navigate away or bypass `onFiles`, a text paste that bypasses consumer interception, changed submit/token semantics, a trigger query that alters typed text, a key that picks a row from an earlier trigger query, a menu that reopens after a send, a Return key label that changes what Enter does, or an `enterKeyHint` type that accepts any string. || Governing rules | `architecture:public-component-api/INV1`, `INV2`–`INV4`, `INV25`; `architecture:interaction-modality/INV1–INV4`; `architecture:knowledge-contracts/INV11, INV16`; `spec:AST-002`; `spec:AST-029`; `component:TextInput/FR16, DEC-1`; rubric B15. |@@ -98,25 +100,25 @@ imperative editing handle.## Behavioral and layout contract-| ID | Invariant | Basis |-| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |-| FR1 | Every user or imperative edit that changes serialized content MUST update empty state and emit the effective value through the active `onChange` channel. Implementation gap: `handleRef.insertToken` inserts the token without emitting the value through `onChange` or updating empty state, so the placeholder stays visible. | Shipped `onChange` contract, imperative handle, and ChatDictation callsite. |-| FR2 | Enter without Shift MUST submit one trimmed non-empty draft and clear it unless the event is composing, the trigger menu consumes it, or a consumer prevents default. | Shipped implementation and consumer docs. |-| FR3 | Shift+Enter and mid-text history arrows MUST retain native multiline editing behavior. | Shipped implementation and focused tests. |-| FR4 | `value` supplied directly on ChatComposerInput MUST win over ChatComposer context, while an emitted echo MUST NOT rebuild the DOM or move the caret. | Shipped controlled precedence and regression tests. |-| FR5 | Plain-text paste precedence MUST be consumer `onPaste` → configured/default paste-as-token → plain insertion. Implementation gap: a paste whose selection starts inside a token inserts the text after that token without calling `onPaste`. | Public callback meaning and objective callback composition. |-| FR6 | File paste and file drop MUST prevent native insertion/navigation and deliver the same ordered `File[]` to `onFiles`; disabled editors MUST NOT emit file callbacks. Implementation gap: a file paste whose selection starts inside a token never reaches `onFiles`. | Shipped public `onFiles` contract and consumer docs. |-| FR7 | Trigger-menu keyboard handling MUST run before consumer and built-in editor handling; IME composition MUST never submit. | Shipped interaction contract and tests. |-| FR8 | History recall MUST operate only at the draft boundaries and MUST restore the pending draft after stepping past the newest item. | Shipped behavior and tests. |-| FR9 | The root MUST keep forwarding its ref, BaseProps attributes, and styling seams; the imperative handle remains separate in `handleRef`. | Released public API and `architecture:public-component-api`. |-| FR10 | A trigger activates when its character starts the text or follows a space, a tab, or a line break, and its query runs from after that character to the caret. Inside an active multi-word query, FR11 limits which characters activate. A no-break space, such as the one after an inserted token, is not a boundary. A single-token query ends at a space, a tab, or a line break. Implementation gap: a trigger character that begins a text node activates whatever precedes it, such as an `@` typed directly after an inserted token and before its trailing no-break space. | Shipped trigger detection; DEC-1. |-| FR11 | A trigger with `hasMultiWordQuery: true` keeps its query through spaces and punctuation. The query ends only at a line break, past an implementation-owned length bound of at least 64 characters, or where the same trigger's character after a space, a tab, or a line break starts a new query; no word count, punctuation list, or termination callback applies. Inside an active multi-word query, another trigger's character does not activate under FR10, so the query continues through it. | DEC-1. |-| FR12 | Ending a trigger query MUST leave the typed text unchanged. Only an explicit pick of a current row replaces the range from the trigger character to the caret. | DEC-1. |-| FR13 | While a newer search for the active query is pending, Enter without Shift submits the draft as typed and MUST NOT pick a row; no key picks a row returned for an earlier query. Results for a superseded query, or arriving after a pick, dismissal, submission, or the query ending, are discarded, so the menu never reopens over a sent or cleared draft. This applies to every trigger. | DEC-1; reference chat composer behavior. |-| FR14 | When a multi-word query settles with no matches, the menu is hidden unless the trigger supplies `emptySearchText`. A single-token query with no matches shows the empty message. | DEC-1. |-| FR15 | Keys pressed during IME composition MUST NOT pick a row or move the highlighted row. | DEC-1; FR7. |-| FR16 | Escape on a visible menu dismisses it, and the menu stays hidden while the same query keeps growing from the same trigger. While open, the menu stays open for a press on the editor or in the menu and closes for a press elsewhere (`architecture:layer-runtime`). | DEC-1. |-| FR17 | The editor carries `enterkeyhint`: the `enterKeyHint` value when one is set, otherwise `send`, because Enter sends (FR2). `enterKeyHint` takes the closed union `EnterKeyHint` (`component:TextInput` FR16), so TypeScript rejects any other value. The hint only labels the key: FR2 and FR3 decide what Enter and Shift+Enter do whatever it says, so a composer whose `onKeyDown` makes Enter insert a line break passes `enter`. ChatComposer's default input carries the same default. Implementation gap: the editor sets no `enterkeyhint`, and ChatComposerInput accepts no `enterKeyHint`. | DEC-2; `component:TextInput` DEC-1 |+| ID | Invariant | Basis |+| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |+| FR1 | Every user or imperative edit that changes serialized content MUST update empty state and emit the effective value through the active `onChange` channel. Implementation gap: `handleRef.insertToken` inserts the token without emitting the value through `onChange` or updating empty state, so the placeholder stays visible. | Shipped `onChange` contract, imperative handle, and ChatDictation callsite. |+| FR2 | Enter without Shift MUST submit one trimmed non-empty draft and clear it unless the event is composing, the trigger menu consumes it, or a consumer prevents default. | Shipped implementation and consumer docs. |+| FR3 | Shift+Enter and mid-text history arrows MUST retain native multiline editing behavior. | Shipped implementation and focused tests. |+| FR4 | `value` supplied directly on ChatComposerInput MUST win over ChatComposer context, while an emitted echo MUST NOT rebuild the DOM or move the caret. | Shipped controlled precedence and regression tests. |+| FR5 | Plain-text paste precedence MUST be consumer `onPaste` → configured/default paste-as-token → plain insertion. Implementation gap: a paste whose selection starts inside a token inserts the text after that token without calling `onPaste`. | Public callback meaning and objective callback composition. |+| FR6 | File paste and file drop MUST prevent native insertion/navigation and deliver the same ordered `File[]` to `onFiles`; disabled editors MUST NOT emit file callbacks. Implementation gap: a file paste whose selection starts inside a token never reaches `onFiles`. | Shipped public `onFiles` contract and consumer docs. |+| FR7 | Trigger-menu keyboard handling MUST run before consumer and built-in editor handling; IME composition MUST never submit. | Shipped interaction contract and tests. |+| FR8 | History recall MUST operate only at the draft boundaries and MUST restore the pending draft after stepping past the newest item. | Shipped behavior and tests. |+| FR9 | The root MUST keep forwarding its ref, BaseProps attributes, and styling seams; the imperative handle remains separate in `handleRef`. | Released public API and `architecture:public-component-api`. |+| FR10 | A trigger activates when its character starts the text or follows a space, a tab, or a line break, and its query runs from after that character to the caret. Inside an active multi-word query, FR11 limits which characters activate. A no-break space, such as the one after an inserted token, is not a boundary. A single-token query ends at a space, a tab, or a line break. Implementation gap: a trigger character that begins a text node activates whatever precedes it, such as an `@` typed directly after an inserted token and before its trailing no-break space. | Shipped trigger detection; DEC-1. |+| FR11 | A trigger with `hasMultiWordQuery: true` keeps its query through spaces and punctuation. The query ends only at a line break, past an implementation-owned length bound of at least 64 characters, or where the same trigger's character after a space, a tab, or a line break starts a new query; no word count, punctuation list, or termination callback applies. Inside an active multi-word query, another trigger's character does not activate under FR10, so the query continues through it. | DEC-1. |+| FR12 | Ending a trigger query MUST leave the typed text unchanged. Only an explicit pick of a current row replaces the range from the trigger character to the caret. | DEC-1. |+| FR13 | While a newer search for the active query is pending, Enter without Shift submits the draft as typed and MUST NOT pick a row; no key picks a row returned for an earlier query. Results for a superseded query, or arriving after a pick, dismissal, submission, or the query ending, are discarded, so the menu never reopens over a sent or cleared draft. This applies to every trigger. | DEC-1; reference chat composer behavior. |+| FR14 | When a multi-word query settles with no matches, the menu is hidden unless the trigger supplies `emptySearchText`. A single-token query with no matches shows the empty message. | DEC-1. |+| FR15 | Keys pressed during IME composition MUST NOT pick a row or move the highlighted row. | DEC-1; FR7. |+| FR16 | Escape on a visible menu dismisses it, and the menu stays hidden while the same query keeps growing from the same trigger. While open, the menu stays open for a press on the editor or in the menu and closes for a press elsewhere (`architecture:layer-runtime`). | DEC-1. |+| FR17 | The editor carries `enterkeyhint`: the `enterKeyHint` value when one is set, otherwise `send`, because Enter sends (FR2). `enterKeyHint` takes the closed union `EnterKeyHint` (`component:TextInput` FR16), so TypeScript rejects any other value. The hint only labels the key: FR2 and FR3 decide what Enter and Shift+Enter do whatever it says, so a composer whose `onKeyDown` makes Enter insert a line break passes `enter`. ChatComposer's default input carries the same default. | DEC-2; `component:TextInput` DEC-1 |### Allowed variation@@ -181,16 +183,16 @@ add a theming target or decide a new visual state.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- |-| FR1, ORD1–ORD2 | focused imperative insertion and controlled-sync tests; `ImperativeInsertion` play | empty → inserted text; controlled echo; external override | Text appears only in the DOM, placeholder remains, callback is stale, or the caret jumps. | `audit:ChatComposerInput/behavior` |-| FR2–FR3, FR7–FR8, AR3 | focused keyboard, IME, trigger, and history tests | Enter; Shift+Enter; composition; cancelled key; boundary and mid-text arrows | A key submits twice, submits during composition, or steals native editing. | `audit:ChatComposerInput/interaction` |-| FR10–FR16, AR5 | focused trigger-query and trigger keyboard tests; "keeps the trigger menu open on a press in the editor or the menu, closes it on a press elsewhere" | single-token; multi-word; line break; length bound; pending search; no matches; IME; Escape | A query ends early or alters text, Enter picks an earlier query's row or fails to submit while a search is pending, a late result reopens the menu after a send, or a hidden menu consumes keys. | `audit:ChatComposerInput/interaction` |-| FR5, ORD4 | focused long-paste interception tests | consumer handled; token conversion; plain insertion | Consumer interception is skipped or multiple insertion paths run. | `audit:ChatComposerInput/behavior` |-| FR6, ORD5, AR2 | focused paste/drop tests and `FileDrop` play | paste; drop; disabled | Files navigate away, insert into the editor, bypass `onFiles`, or emit while disabled. | `audit:ChatComposerInput/behavior` |-| AR1, AR4 | role/name/ARIA tests plus exact-head accessibility and visual gates | textbox; combobox; disabled; keyboard focus | Name, role, multiline, expanded, disabled, or visible focus semantics regress. | `audit:ChatComposerInput/accessibility` |-| FR9 | ref, target, package, and repository checks | ref; BaseProps; xstyle; className; style | Root ownership or a styling seam moves or disappears. | `audit:ChatComposerInput/api` |-| FR17 | Evidence gap until built: render tests that the editor carries `enterkeyhint="send"` by default, the set value when `enterKeyHint` is passed, and `send` inside ChatComposer's default input, and that Enter submits under every label; a type test that `enterKeyHint` rejects an arbitrary string; a real-browser touch-emulation check that the focused editor carries the attribute | default; `enter`; inside ChatComposer; a phone viewport with touch emulation | A missing or wrong `enterkeyhint`, a label that stops Enter from submitting, or a type that accepts `string` fails. | `audit:ChatComposerInput/api` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- |+| FR1, ORD1–ORD2 | focused imperative insertion and controlled-sync tests; `ImperativeInsertion` play | empty → inserted text; controlled echo; external override | Text appears only in the DOM, placeholder remains, callback is stale, or the caret jumps. | `audit:ChatComposerInput/behavior` |+| FR2–FR3, FR7–FR8, AR3 | focused keyboard, IME, trigger, and history tests | Enter; Shift+Enter; composition; cancelled key; boundary and mid-text arrows | A key submits twice, submits during composition, or steals native editing. | `audit:ChatComposerInput/interaction` |+| FR10–FR16, AR5 | focused trigger-query and trigger keyboard tests; "keeps the trigger menu open on a press in the editor or the menu, closes it on a press elsewhere" | single-token; multi-word; line break; length bound; pending search; no matches; IME; Escape | A query ends early or alters text, Enter picks an earlier query's row or fails to submit while a search is pending, a late result reopens the menu after a send, or a hidden menu consumes keys. | `audit:ChatComposerInput/interaction` |+| FR5, ORD4 | focused long-paste interception tests | consumer handled; token conversion; plain insertion | Consumer interception is skipped or multiple insertion paths run. | `audit:ChatComposerInput/behavior` |+| FR6, ORD5, AR2 | focused paste/drop tests and `FileDrop` play | paste; drop; disabled | Files navigate away, insert into the editor, bypass `onFiles`, or emit while disabled. | `audit:ChatComposerInput/behavior` |+| AR1, AR4 | role/name/ARIA tests plus exact-head accessibility and visual gates | textbox; combobox; disabled; keyboard focus | Name, role, multiline, expanded, disabled, or visible focus semantics regress. | `audit:ChatComposerInput/accessibility` |+| FR9 | ref, target, package, and repository checks | ref; BaseProps; xstyle; className; style | Root ownership or a styling seam moves or disappears. | `audit:ChatComposerInput/api` |+| FR17 | `ChatComposerInput.test.tsx` touch keyboard Return key suite (`send` by default, the set value, `send` inside ChatComposer's default input, Enter submits under every label); `ChatComposerInput.public.test.ts`, run by `pnpm typecheck`, for `EnterKeyHint` rejecting an arbitrary or unnarrowed string; `ChatComposerReturnKey.a11y.chromium.spec.ts` for the attribute on the editor a tap focuses | default; `enter`; inside ChatComposer; a phone viewport with touch emulation | A missing or wrong `enterkeyhint`, a label that stops Enter from submitting, or a type that accepts `string` fails. | `audit:ChatComposerInput/api` |## Decision logdiff --git a/packages/core/api-report.md b/packages/core/api-report.mdindex 99ade4234f..aa30a74bee 100644--- a/packages/core/api-report.md+++ b/packages/core/api-report.md@@ -397,6 +397,7 @@ component ChatComposerDrawer(props: ChatComposerDrawerProps)inherits AriaAttributes, DOMAttributes, HTMLAttributescomponent ChatComposerInput(props: ChatComposerInputProps)prop debounceMs?: number = 150+ prop enterKeyHint?: EnterKeyHint = 'send'prop handleRef?: React.Ref<ChatComposerInputHandle>prop hasHistory?: boolean = trueprop isDisabled?: boolean = false@@ -2387,6 +2388,7 @@ component Text(props: TextProps)prop xstyle?: StyleXStylesinherits AriaAttributes, DOMAttributes, HTMLAttributescomponent TextArea(props: TextAreaProps)+ prop autoCapitalize?: AutoCapitalizeprop autoComplete?: React.TextareaHTMLAttributes<HTMLTextAreaElement>['autoComplete']prop changeAction?: (value: string, e: ChangeEvent<HTMLTextAreaElement>) => void | Promise<void>prop containerClassName?: string@@ -2397,9 +2399,12 @@ component TextArea(props: TextAreaProps)prop controlXstyle?: StyleXStylesprop description?: stringprop disabledMessage?: string+ prop enterKeyHint?: EnterKeyHint+ prop hasAutoCorrect?: booleanprop hasAutoFocus?: boolean = falseprop hasSpellCheck?: boolean = trueprop htmlName?: string+ prop inputMode?: InputModeprop isDisabled?: boolean = falseprop isLabelHidden?: boolean = falseprop isLoading?: boolean = false@@ -2424,6 +2429,7 @@ component TextArea(props: TextAreaProps)prop width?: SizeValueinherits AriaAttributes, DOMAttributes, HTMLAttributescomponent TextInput(props: TextInputProps)+ prop autoCapitalize?: AutoCapitalizeprop autoComplete?: React.InputHTMLAttributes<HTMLInputElement>['autoComplete']prop changeAction?: (value: string, e: ChangeEvent<HTMLInputElement>) => void | Promise<void>prop containerClassName?: string@@ -2434,9 +2440,13 @@ component TextInput(props: TextInputProps)prop controlXstyle?: StyleXStylesprop description?: stringprop disabledMessage?: string+ prop enterKeyHint?: EnterKeyHint+ prop hasAutoCorrect?: booleanprop hasAutoFocus?: boolean = falseprop hasClear?: boolean = false+ prop hasSpellCheck?: booleanprop htmlName?: string+ prop inputMode?: InputModeprop isDisabled?: boolean = falseprop isLabelHidden?: boolean = falseprop isLoading?: boolean = false@@ -3502,6 +3512,7 @@ interface AppShellVariantMaptype AspectRatioFit = 'cover' | 'contain' | 'center'interface AspectRatioProps extends BaseProps<HTMLDivElement> (props of AspectRatio)type AspectRatioShape = 'rectangle' | 'ellipse'+type AutoCapitalize = 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'interface AvatarGroupContextValuenumericSize: numberoverlap: number@@ -4212,6 +4223,7 @@ type ElementSize = 'sm' | 'md' | 'lg'interface EmptyOperatorValuetype: 'empty'interface EmptyStateProps extends BaseProps<HTMLDivElement> (props of EmptyState)+type EnterKeyHint = 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'interface EntityListOperatorValueisArbitraryStringAllowed?: boolean = falserenderItem?: (item: SearchableItem) => ReactNode@@ -4485,6 +4497,7 @@ interface InputGroupContextValueinterface InputGroupProps extends Omit<BaseProps<HTMLDivElement>, 'children'> (props of InputGroup)type InputGroupSize = 'sm' | 'md' | 'lg'interface InputGroupTextProps extends BaseProps<HTMLDivElement> (props of InputGroupText)+type InputMode = 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'type InputSize = 'sm' | 'md' | 'lg'interface InputStatusmessage?: string@@ -5425,7 +5438,7 @@ interface TableTreeRowMetaisExpanded: booleanlevel: numbertype TableVerticalAlign = 'middle' | 'top' | 'bottom'-interface TextAreaProps extends Omit<FieldInputBaseProps, 'onChange' | 'defaultValue'> (props of TextArea)+interface TextAreaProps extends Omit<FieldInputBaseProps, 'onChange' | 'defaultValue'>, TextEntryTraitProps (props of TextArea)type TextAreaSize = 'sm' | 'md' | 'lg'interface TextAreaStatusmessage?: string@@ -5440,13 +5453,13 @@ interface TextColorMapprimary: truesecondary: truetype TextDisplay = 'inline' | 'block'-interface TextInputProps extends Omit<FieldInputBaseProps, 'onChange' | 'defaultValue'> (props of TextInput)+interface TextInputProps extends Omit<FieldInputBaseProps, 'onChange' | 'defaultValue'>, TextEntryTraitProps (props of TextInput)type TextInputSize = keyof typeof sizeStylesinterface TextInputStatusmessage?: stringtype: InputStatusTypetype TextInputStatusType = 'warning' | 'error' | 'success'-type TextInputType = 'text' | 'password' | 'email'+type TextInputType = 'text' | 'password' | 'email' | 'search' | 'tel' | 'url'type TextJustify = 'start' | 'center' | 'end'interface TextProps extends Omit<BaseProps, 'children'> (props of Text)type TextSize = '4xs' | '3xs' | '2xs' | 'xsm' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl'@@ -6947,6 +6960,8 @@ EmptyStateProps (.)### Also exported from an earlier entry point```text+AutoCapitalize (.)+EnterKeyHint (.)Field (.)FieldContainerStyleProps (.)FieldControlStyleProps (.)@@ -6963,6 +6978,7 @@ FieldStatusType (.)FieldStatusVariant (.)FieldStatusVariantMap (.)InputClearButton (.)+InputMode (.)InputSize (.)InputStatus (.)InputStatusType (.)diff --git a/packages/core/src/Chat/ChatComposerInput.doc.mjs b/packages/core/src/Chat/ChatComposerInput.doc.mjsindex 5668085cee..63666f0e6b 100644--- a/packages/core/src/Chat/ChatComposerInput.doc.mjs+++ b/packages/core/src/Chat/ChatComposerInput.doc.mjs@@ -157,6 +157,13 @@ export const docs = {description:'Key-down handler invoked before the built-in Enter/history behavior (after any open trigger menu). The seam for platform-specific keys: call event.preventDefault() to suppress the default submit (e.g. newline on a touch keyboard), or act on the event yourself to add behavior (e.g. submit on Cmd/Ctrl+Enter). IME composition is always respected; Enter never submits mid-composition.',},+ {+ name: 'enterKeyHint',+ type: "'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'",+ description:+ 'What the Return key of a touch keyboard says (the native enterkeyhint). Enter sends the message, so it defaults to send and iOS shows its Send key. When onKeyDown makes Enter insert a line break on touch keyboards, pass enter so the key shows Return again.',+ default: "'send'",+ },],};@@ -187,6 +194,8 @@ export const docsZh = {onSubmit: '用户不按 Shift 按 Enter 时调用。序列化值包含标记占位符。',onKeyDown:'在内置 Enter/历史处理之前(在打开的触发菜单之后)调用的按键处理器。平台特定按键的接缝:调用 event.preventDefault() 可抑制默认提交(例如触控键盘上插入换行),或自行处理事件以添加行为(例如 Cmd/Ctrl+Enter 提交)。始终尊重输入法组字状态——组字过程中 Enter 永不提交。',+ enterKeyHint:+ '触屏键盘回车键上显示的内容(原生 enterkeyhint)。Enter 会发送消息,因此默认为 send,iOS 显示“发送”键。当 onKeyDown 让触屏键盘上的 Enter 插入换行时,传入 enter 让按键恢复为回车。',},};@@ -219,5 +228,7 @@ export const docsDense = {'Enter w/o Shift handler; serialized value includes token placeholders',onKeyDown:'keydown handler before built-in Enter/history (after trigger menu); preventDefault() to suppress default submit (touch newline) or act on event to add behavior (Cmd/Ctrl+Enter). IME composition always respected',+ enterKeyHint:+ 'touch keyboard Return key label (enterkeyhint); default send since Enter sends; pass enter when onKeyDown makes Enter a newline on touch',},};diff --git a/packages/core/src/Chat/ChatComposerInput.public.test.ts b/packages/core/src/Chat/ChatComposerInput.public.test.tsnew file mode 100644index 0000000000..06132a81c4--- /dev/null+++ b/packages/core/src/Chat/ChatComposerInput.public.test.ts@@ -0,0 +1,44 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file ChatComposerInput.public.test.ts+ * @input The package entry's ChatComposerInputProps and EnterKeyHint+ * @output Guards that the composer's `enterKeyHint` takes the text fields'+ * closed, exported union of HTML-standard Return-key values. 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 {ChatComposerInputProps, EnterKeyHint} from '../index';++type ReturnKey = Pick<ChatComposerInputProps, 'enterKeyHint'>;++describe('ChatComposerInput enterKeyHint type', () => {+ it('is the exported closed union of the HTML-standard values', () => {+ expectTypeOf<+ NonNullable<ChatComposerInputProps['enterKeyHint']>+ >().toEqualTypeOf<EnterKeyHint>();+ expectTypeOf<+ NonNullable<ChatComposerInputProps['enterKeyHint']>+ >().toEqualTypeOf<+ 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'+ >();+ });++ it('rejects a string outside the standard values', () => {+ const returnKey: ReturnKey = {+ // @ts-expect-error -- not a Return key the HTML standard defines+ enterKeyHint: 'submit',+ };+ expectTypeOf(returnKey).toEqualTypeOf<ReturnKey>();+ });++ it('rejects 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 returnKey: ReturnKey = {enterKeyHint: fromServer};+ expectTypeOf(returnKey).toEqualTypeOf<ReturnKey>();+ });+});diff --git a/packages/core/src/Chat/ChatComposerInput.test.tsx b/packages/core/src/Chat/ChatComposerInput.test.tsxindex eafcc79f8a..d51141c1b7 100644--- a/packages/core/src/Chat/ChatComposerInput.test.tsx+++ b/packages/core/src/Chat/ChatComposerInput.test.tsx@@ -354,6 +354,55 @@ describe('ChatComposerInput', () => {});});+ describe('touch keyboard Return key', () => {+ it('labels the Return key Send by default, since Enter sends', () => {+ render(<ChatComposerInput onSubmit={() => {}} />);+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'enterkeyhint',+ 'send',+ );+ });++ it('takes enterKeyHint for a composer whose Enter inserts a line break', () => {+ render(<ChatComposerInput onSubmit={() => {}} enterKeyHint="enter" />);+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'enterkeyhint',+ 'enter',+ );+ });++ it('labels the default input of ChatComposer Send', () => {+ render(<ChatComposer onSubmit={() => {}} />);+ expect(screen.getByRole('textbox')).toHaveAttribute(+ 'enterkeyhint',+ 'send',+ );+ });++ it.each([+ 'enter',+ 'done',+ 'go',+ 'next',+ 'previous',+ 'search',+ 'send',+ ] as const)(+ 'only labels the key: Enter still submits under %s',+ enterKeyHint => {+ const onSubmit = vi.fn();+ render(+ <ChatComposerInput onSubmit={onSubmit} enterKeyHint={enterKeyHint} />,+ );+ const textbox = screen.getByRole('textbox');+ textbox.textContent = 'hello';+ fireEvent.input(textbox);+ fireEvent.keyDown(textbox, {key: 'Enter'});+ expect(onSubmit).toHaveBeenCalledWith('hello');+ },+ );+ });+describe('Enter submit behavior', () => {it('does not submit on Enter while IME composition is in progress', () => {const onSubmit = vi.fn();diff --git a/packages/core/src/Chat/ChatComposerInput.tsx b/packages/core/src/Chat/ChatComposerInput.tsxindex 88988c7438..d6ba55e33b 100644--- a/packages/core/src/Chat/ChatComposerInput.tsx+++ b/packages/core/src/Chat/ChatComposerInput.tsx@@ -68,6 +68,7 @@ import {import {Badge, type BadgeProps} from '../Badge';import {useChatComposerContext} from './ChatContext';import {themeProps} from '../utils/themeProps';+import type {EnterKeyHint} from '../Field/textEntryTraits';import {registerEnglishFallback,useComponentTranslator,@@ -247,6 +248,14 @@ export interface ChatComposerInputProps extends Omit<* never submits while a composition is in progress.*/onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;+ /**+ * What the Return key of a touch keyboard says (the native+ * `enterkeyhint`). Enter sends the message, so the key says so: iOS shows+ * its Send key. When `onKeyDown` makes Enter insert a line break on touch+ * keyboards, pass `'enter'` so the key shows Return again.+ * @default 'send'+ */+ enterKeyHint?: EnterKeyHint;}// =============================================================================@@ -373,6 +382,7 @@ export function ChatComposerInput(props: ChatComposerInputProps) {onFiles,onSubmit = composerCtx?.onSubmit,onKeyDown: onKeyDownProp,+ enterKeyHint = 'send',xstyle,className,style,@@ -941,6 +951,7 @@ export function ChatComposerInput(props: ChatComposerInputProps) {// Explicit in both states: losing editability must not lose focus.tabIndex={0}contentEditable={!isDisabled}+ enterKeyHint={enterKeyHint}suppressContentEditableWarningonInput={handleInput}onClick={handleEditorClick}diff --git a/packages/core/src/Chat/__tests__/ChatComposerReturnKey.a11y.chromium.spec.ts b/packages/core/src/Chat/__tests__/ChatComposerReturnKey.a11y.chromium.spec.tsnew file mode 100644index 0000000000..a6e6ef192d--- /dev/null+++ b/packages/core/src/Chat/__tests__/ChatComposerReturnKey.a11y.chromium.spec.ts@@ -0,0 +1,72 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @pr-a11y scope ^(packages/core/src/Chat/ChatComposer|packages/core/src/Field/textEntryTraits|apps/storybook/stories/ChatComposer)++/**+ * @file ChatComposerReturnKey.a11y.chromium.spec.ts+ * @input The `Core/ChatComposer` Simplest and EnterBehavior stories in a built+ * Storybook, in Chromium on a phone viewport with touch emulation.+ * @output Real-browser proof of component:ChatComposerInput FR17. The editor a+ * finger focuses labels the touch keyboard's Return key Send by default. It+ * takes the label a caller passes, such as Return where Enter inserts a line+ * break.+ * @position Runs in pr-a11y when ChatComposer, its input, the keyboard traits+ * or their stories change. jsdom has no touch input, so only a browser shows+ * what the editor a tap focuses carries when the keyboard opens.+ */++import {expect, test, type Page} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;+test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});+test.afterAll(async () => {+ await storybook?.close();+});++test.use({+ hasTouch: true,+ isMobile: true,+ viewport: {width: 390, height: 844},+});++/** Opens a story, taps its editor and returns its Return-key label. */+async function tapEditor(page: Page, story: string): Promise<string | null> {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-chatcomposer--${story}&viewMode=story`,+ );+ // The emulation is a touch screen, as the stories read it.+ expect(+ await page.evaluate(() => matchMedia('(pointer: coarse)').matches),+ ).toBe(true);+ // Present and painted before anything is judged.+ const editor = page.getByRole('textbox');+ await expect(editor).toBeVisible();+ const box = await editor.boundingBox();+ expect(box?.width ?? 0).toBeGreaterThan(0);+ expect(box?.height ?? 0).toBeGreaterThan(0);+ await editor.tap();+ await expect(editor).toBeFocused();+ return editor.getAttribute('enterkeyhint');+}++test('the editor a tap focuses labels the Return key Send by default', async ({+ page,+}) => {+ expect(await tapEditor(page, 'simplest')).toBe('send');+});++test('the editor a tap focuses carries the label its caller passes', async ({+ page,+}) => {+ // The story's Enter inserts a line break on a touch screen, so it passes+ // `enter` and the key reads Return.+ expect(await tapEditor(page, 'enter-behavior')).toBe('enter');+});