Skip to content

fix(Select): guard IME composition-commit Enter (keyCode 229)#2082

Closed
greymoth-jp wants to merge 1 commit into
huntabyte:mainfrom
greymoth-jp:fix/select-ime-enter-keycode-229
Closed

fix(Select): guard IME composition-commit Enter (keyCode 229)#2082
greymoth-jp wants to merge 1 commit into
huntabyte:mainfrom
greymoth-jp:fix/select-ime-enter-keycode-229

Conversation

@greymoth-jp

Copy link
Copy Markdown

Problem

SelectInputState.onkeydown (in select.svelte.ts, shared by both the Select and Combobox inputs) commits the highlighted item on Enter as long as the user is not composing:

if (e.key === kbd.ENTER && !e.isComposing) {

In Safari with a Japanese (or other CJK) IME, the Enter that commits the IME composition arrives with isComposing === false and keyCode === 229. So !e.isComposing is true, the guard misses it, and the highlighted item gets selected (and the menu closes) while the user only meant to confirm what they typed.

Command already guards against exactly this in command.svelte.ts, with a comment explaining why:

// e.keyCode === 229 is for the Japanese IME && Safari as `isComposing` does not
// work with Japanese IME and Safari in combination.
if (!e.isComposing && e.keyCode !== 229) {

The select input handler was missing the keyCode === 229 half of that check, so Select/Combobox and Command behave differently for the same IME.

Change

  • Add && e.keyCode !== 229 to the Enter guard in select.svelte.ts, mirroring Command.
  • Add a Combobox regression test: with item 2 highlighted, an Enter delivered with keyCode === 229 leaves the menu open and selects nothing, while a normal Enter still commits the selection.

The fix lives in SelectInputState, which is also used by combobox-input.svelte, so this covers both components.

Verification

I traced the keydown path to confirm the fix: without it, the keyCode === 229 Enter passes the old guard and reaches toggleItem + handleClose; with it, the Enter branch is skipped and the event falls through to the INTERACTION_KEYS early return, so the menu stays open and nothing is selected. A plain Enter (keyCode 13) still selects, which the existing "select item with the enter key" test covers.

I was not able to run the browser test suite locally (the pnpm postinstall scripts fail on my Windows setup and the runner needs a downloaded browser), so the new test is unrun here. It follows the existing dispatchEvent idiom used in the accordion tests and the Enter/highlight assertions from the existing combobox test, so CI should exercise it. Happy to adjust the test or its placement.

@changeset-bot

changeset-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 00824a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bits-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 00824a6

@greymoth-jp

Copy link
Copy Markdown
Author

Closing this. It's a minor IME composition guard with failing checks I haven't resolved, so I'll take it off your queue. Thanks for the project.

@greymoth-jp greymoth-jp closed this Jul 3, 2026
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.

1 participant