Repository navigation
fix(Typeahead): guard Enter/Escape/arrow keys against IME composition - #4860
Merged
cixzhang merged 1 commit intoAug 11, 2026
Merged
Conversation
BaseTypeahead's keydown handler treated every Enter as "accept the
highlighted suggestion" with no composition guard. The browser fires
keydown (isComposing: true, or legacy keyCode 229) before
compositionend commits the pending IME syllable -- so the Enter that
a CJK IME user presses to confirm a composition both selected the
highlighted result and cleared the input via handleSelect's
setQuery(''), leaving the still-composing syllable to land in the
freshly-cleared field and become its own spurious second selection.
Everything built on BaseTypeahead (Typeahead, Tokenizer, PowerSearch's
content-search field) inherits the fix. Also guarded the same gap in
PowerSearchEditPopover's Enter-to-save handler, which had the same
issue typing a CJK filter value. Both use the isImeKeyEvent helper
already established for this exact purpose in useFocusTrap.ts and
already applied in ChatComposerInput.
Closes meta#4828.
|
@HelloOjasMutreja is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsPowerSearch (@astryxdesign/core) · View in Storybook
Typeahead (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. PowerSearch - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
HelloOjasMutreja
marked this pull request as ready for review
August 10, 2026 19:38
HelloOjasMutreja
requested review from
cixzhang and
imdreamrunner
as code owners
August 10, 2026 19:38
cixzhang
approved these changes
Aug 11, 2026
cixzhang
left a comment
Contributor
There was a problem hiding this comment.
Thanks, good check for i18n.
cixzhang
enabled auto-merge (squash)
August 11, 2026 00:28
This was referenced Aug 11, 2026
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
Closes #4828.
Typing with an IME (Korean/Japanese/Chinese) in
BaseTypeahead(and everything built on it:Typeahead,Tokenizer, PowerSearch's free-text content-search field) and pressing Enter to commit the composition is misinterpreted as "accept the highlighted suggestion". The pending syllable is then re-committed into the freshly-cleared input, becoming its own separate selection.Root cause
BaseTypeahead.handleKeyDown'scase 'Enter'had no composition guard. The browser event order when an IME commits on Enter is:keydown(isComposing: true, or legacykeyCode: 229) →compositionend(writes the pending syllable) →input. The keydown reacheshandleSelect, which firesonChangeandsetQuery(''), clearing the controlled input — but the composition is still live on that DOM node, socompositionendthen commits the pending syllable into the now-empty field.This is the same class of bug already fixed for
ChatComposerInput(and documented for overlays generally viaisImeKeyEventinuseFocusTrap.ts) —BaseTypeaheadnever got the same guard.Fix
Added an early-return guard using the existing
isImeKeyEventhelper (useFocusTrap.ts) at the top ofBaseTypeahead.handleKeyDown, before theArrowDown-opens-popover branch and theEnter/Escape/ArrowUp/ArrowDown/Home/Endswitch — an IME candidate window uses all of those keys for its own navigation, not just Enter.Also guarded the same gap in
PowerSearchEditPopover's Enter-to-save handler, which would otherwise close the popover mid-composition while typing a CJK filter value (flagged in the issue as a second unguarded site).Test notes
Added regression tests in both
Typeahead.test.tsxandPowerSearchEditPopover.test.tsx: a composing Enter (bothisComposing: trueand legacykeyCode: 229) does not fire selection/save, and a real Enter afterward still works normally. Verified both fail against the pre-fix code and pass with the fix.Test plan
vitest run packages/core/src/Typeahead— 50/50 passingvitest run packages/core/src/PowerSearch— 150/150 passingvitest run packages/core/src/Tokenizer— 61/61 passing (built onBaseTypeahead)eslintclean (pre-existing, unrelated wrapper-div warnings elsewhere inPowerSearchEditPopover.tsx)