Skip to content

i18n: systematically guard IME composition across text-input components #4892

Closed

Description

@nynexman4464

Problem

Text-input components that handle keydown (Enter/Escape/arrows) can misfire while an IME (Korean/Japanese/Chinese) composition is live. Pressing Enter to commit a composition is misread as a command (accept suggestion, save, submit), because the browser fires keydown with isComposing: true (or legacy keyCode: 229) BEFORE compositionend writes the pending syllable.

This has now been fixed reactively in three places, one at a time:

The shared helper already exists: isImeKeyEvent in useFocusTrap.ts. The gap is that there's no systematic guarantee every keydown-handling text input uses it — each site has been patched only after a user hit the bug.

Goal

Make IME-composition safety a property we enforce, not a bug we keep rediscovering. Audit every component that reads Enter/Escape/arrow/Home/End on a text input or contenteditable and confirm it guards with isImeKeyEvent (or equivalent). Candidates to check beyond the three already fixed: TextArea/TextInput (if they have keydown commit behavior), SearchInput, ComboBox/Selector search fields, NumberInput, DateTimeInput segment editing, CommandPalette input, any Chat inputs, and anything else consuming onKeyDown on an editable surface.

Possible approaches (decide during investigation)

  1. A lint rule — flag onKeyDown handlers on text inputs that reference e.key === 'Enter'/'Escape'/arrow keys without an isImeKeyEvent/isComposing guard. Highest leverage; catches new code (incl. AI-generated) at author time.
  2. An interaction test / audit dimension — fire a composing Enter (isComposing: true and keyCode: 229) at each text-input component and assert it does NOT trigger the command action, then a real Enter does. Mirrors how fix(Typeahead): guard Enter/Escape/arrow keys against IME composition #4860 tested it.
  3. A shared input primitive/hook that bakes in the guard, so components can't forget it.

Context

Not an RTL bug (CJK is LTR) and not caught by the pr-rtl audit, which is scoped to layout-direction geometry. This is the input-method dimension of i18n — a distinct class the current tooling doesn't cover. Surfaced by @cixzhang. Related reactive fixes: #4860, #4828.

Activity

  1. self-assigned this
    on Aug 11, 2026
  2. added
    enhancement
    on Aug 11, 2026
  3. nynexman4464 commented on Aug 11, 2026

    @nynexman4464
    ContributorAuthor

    Investigation findings

    Audited every onKeyDown/handleKeyDown site in packages/core/src that branches on command keys (Enter/Escape/arrows/Home/End) and attaches to an editable surface (<input>/<textarea>/contentEditable). Filtered out non-editable keydown sites (buttons, menus, tabs, calendar cells) where an IME can't run.

    Confirmed same-class bugs (unguarded free-text input)

    • Selector (searchable) — the search TextInput's onKeyDown forwards Enter/Escape straight to the shared handler (Selector/hooks.ts), which selects the highlighted option / closes the popover. No isComposing/isImeKeyEvent guard. A CJK user committing a composition with Enter selects an option instead of committing text. Direct analogue of fix(Typeahead): guard Enter/Escape/arrow keys against IME composition #4860.
    • MultiSelector (searchable) — structurally identical search-input path; same unguarded Enter/Escape forward.

    Lower risk (guard is cheap + consistent, but low real-world exposure)

    • NumberInput — commits on Enter, but type="number"; IMEs don't compose CJK text into number fields.
    • Chat useTriggerMenu — operates on a contenteditable; worth confirming its Enter/Escape can't fire mid-composition.

    Ruled out

    • DateInput / DateTimeInput / TimeInput — segmented numeric fields, no free-text composition.
    • All non-editable keydown sites.

    Already guarded

    ChatComposerInput, BaseTypeahead (+Typeahead/Tokenizer/PowerSearch via #4860), Tooltip, Dialog.

    Conclusion

    This is a "no mechanism prevents the next one" problem, not a "find the last few sites" problem — Selector + MultiSelector shipped the same gap after Typeahead was fixed, because nothing enforces the guard. Highest-leverage fix = approach 1 (lint rule): flag any onKeyDown on an editable surface that branches on Enter/Escape/arrows without an isComposing/isImeKeyEvent guard. That catches Selector, MultiSelector, and every future component (incl. AI-generated) at author time.

    Also evaluating consolidating the 4 existing ad-hoc guards (isImeKeyEvent in useFocusTrap.ts + inline isComposing checks) into a single shared primitive so the lint rule has one canonical thing to point at.

  4. added 5 commits that reference this issue on Aug 11, 2026
    8dcbaa4
    5442408
    ffcc49b
    c3e039f
    48f182c
  5. added a commit that references this issue on Aug 17, 2026
    ba74b44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions