Repository navigation
feat(core): add onKeyDown seam to ChatComposerInput for platform-specific keys - #4280
Merged
Merged
Conversation
The composer's key handler unconditionally submitted on Enter (without Shift), so it sent on Enter even on a soft keyboard — where Return should insert a newline rather than strand a multi-line prompt — and it did not guard IME composition, so an Enter used to commit an input-method candidate submitted the message instead. There was no seam to override any of this. Add two additive, backward-compatible props: - shouldSubmitOnEnter?: boolean | ((event) => boolean) (default true) — a fixed policy or per-keystroke predicate; return false to let Enter fall through and insert a line break (desktop-send / touch-newline). - onKeyDown?: (event) => void — runs before the built-in Enter/history handling (after an open trigger menu); preventDefault() to take over. Independently, Enter no longer submits mid-IME-composition (nativeEvent.isComposing, plus the legacy keyCode 229 signal), regardless of shouldSubmitOnEnter.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsChat · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. Chat - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
The composer's key handler unconditionally submitted on Enter (without Shift), so it sent on Enter even on a soft keyboard — where Return should insert a newline rather than strand a multi-line prompt — and it did not guard IME composition, so an Enter used to commit an input-method candidate submitted the message instead. There was also no seam to intercept keys. Expose one general primitive instead of a policy-specific prop: - onKeyDown?: (event) => void — runs before the built-in Enter/history handling (after an open trigger menu). preventDefault() to suppress the default submit (e.g. newline on a touch keyboard); or act on the event without preventDefault() to add behavior (e.g. Cmd/Ctrl+Enter submit) while the default handling still runs for other keys. Independently, Enter no longer submits mid-IME-composition (nativeEvent.isComposing, plus the legacy keyCode 229 signal) — an unconditional correctness fix, not a preference, so it has no prop.
AKnassa
added a commit
to AKnassa/astryx
that referenced
this pull request
Sep 26, 2026
Resolved conflicts: - packages/core/src/Chat/ChatComposerInput.tsx: kept the PR's handleRef.setValue alongside upstream's `focus: focusEditable` (meta#6419/meta#6398 keep an existing in-editor selection on focus); dropped the PR's local placeCaretAtEnd helper in favour of upstream's import from ./chatComposerSelection; handleKeyDown deps keep upstream's onKeyDownProp (meta#4280) and drop onChange, since submit-clear now reports through emitChange. The pending-emissions ledger auto-merged over upstream's one-shot pendingEchoValueRef, next to meta#6419's emitChangeVersionRef. - packages/core/src/Chat/ChatComposerInput.test.tsx: took upstream's imports (waitFor, act, userEvent); the PR's controlled-value and trigger-menu tests auto-merged. - packages/core/src/Chat/ChatComposerInput.doc.mjs: kept the PR's handleRef/value prose in upstream's prettier-wrapped layout, and recast the English/dense em dashes as punctuation per meta#4394. Known fallout, fixed in the follow-up review commit (astracat F2): the required `setValue` member breaks upstream's five-member handle literal in useChatPasteAsToken.test.ts (TS2741 under the core typecheck).
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses finding #9 from the Astryx adoption feedback (#4276):
ChatComposerInputcan't host a composer with platform-specific Enter behavior.The key handler submitted unconditionally on Enter (without Shift):
So it sent on Enter even on a soft keyboard — where Return should insert a newline rather than strand a multi-line prompt — didn't guard IME composition (an Enter used to commit an input-method candidate submitted the message), and offered no seam to intercept keys. The reporter had to keep their own
<textarea>composer.Change
One general seam instead of a policy-specific prop:
onKeyDown?: (event) => void— runs before the built-in Enter/history handling (after any open trigger menu).event.preventDefault()→ suppress the default submit (e.g. newline on a touch keyboard).preventDefault()→ add behavior (e.g. Cmd/Ctrl+Enter to send) while default handling still runs for other keys.Plus an unconditional correctness fix: Enter no longer submits mid-IME-composition (
nativeEvent.isComposing, plus the legacykeyCode === 229). This is a bug fix, not a preference, so it has no prop.Risk / compatibility
Additive and backward-compatible — default behavior is unchanged.
onKeyDownis opt-in; the only behavioral change with no opt-in is the IME guard, which only stops an incorrect submit during composition.Design note: an earlier revision added a
shouldSubmitOnEnterboolean/predicate prop (as the issue suggested); we dropped it. It overlapsonKeyDown, can't express pointer-conditional or shortcut cases without growing, and pre-names one policy in the API.onKeyDown+preventDefault()covers every case (touch newline, Cmd+Enter, Esc-to-blur, …) with one composable primitive.Testing
New
Enter submit behaviortests: IMEisComposingand legacykeyCode 229guards, the touch-newlinepreventDefaultrecipe, the Cmd/Ctrl+Enter add-behavior recipe, andonKeyDownordering. Docs (.doc.mjsen/zh/dense) and theEnterBehaviorStorybook story updated to theonKeyDownrecipe.pnpm build, coretypecheck,typecheck:docs, andpnpm lintclean; full Chat suite green.