Skip to content

useHotkeys: ignore keys that belong to an IME composition - #676

Merged
blvdmitry merged 2 commits into
reshaped-ui:mainfrom
mahirhir:fix/hotkeys-ime-composition
Oct 8, 2026
Merged

blvdmitry merged 2 commits into
reshaped-ui:mainfrom
mahirhir:fix/hotkeys-ime-composition

Conversation

@mahirhir

@mahirhir mahirhir commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

handleWindowKeyDown in useSingletonHotkeys now returns early when e.isComposing is true or e.keyCode === 229, so keys an IME is handling never reach registered hotkeys. With a Japanese, Chinese or Korean IME, the Enter that confirms a conversion no longer makes Autocomplete select the highlighted option or call onEnter. Escape and arrow keys pressed during a composition are skipped the same way.

The keyCode check is for Safari, which fires compositionend before the keydown of the confirming Enter, so isComposing is already false on that event.

Related Issue

Fixes #671

Screenshots / Recordings

None, there is no visual change.

Notes for Reviewers

  • The issue also suggests e.key === "Process". I left it out because the check MDN recommends (isComposing || keyCode === 229) already catches the first and last keydown of a composition, where isComposing is false. Happy to add it if you prefer.
  • The guard sits in the shared window handler, so it applies to every useHotkeys consumer, not only Autocomplete. Skipped keys are also not added to the pressed-key map.
  • New story useHotkeys > ignores IME composition dispatches a composing Enter and a Safari-style Enter (keyCode: 229, isComposing: false) on window, then a normal Enter. On main it fails (the hotkey is called twice for the IME keydowns); with the change it passes.
  • Locally: vitest --project=storybook 594 tests passed, --project=unit 181 passed, oxlint, oxfmt and tsc clean. I have not tried it with a real IME in a browser.
  • Added a patch changeset.

mahirhir and others added 2 commits October 7, 2026 07:45
The Enter that confirms an IME conversion reached registered hotkeys, so Autocomplete selected the highlighted option and called onEnter with unfinished text. Return early in handleWindowKeyDown when isComposing is set or keyCode is 229 (Safari fires the confirming keydown after compositionend).

Fixes reshaped-ui#671
@blvdmitry

Copy link
Copy Markdown
Contributor

Looks good, thanks for the contribution 🙌

@blvdmitry
blvdmitry merged commit 6150f4f into reshaped-ui:main Oct 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IME composition Enter triggers useHotkeys handlers (Autocomplete selects option / fires onEnter)

2 participants