Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/select-ime-enter-keycode-229.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix(Select): don't commit the highlighted item on an IME composition-commit Enter in Safari (`keyCode === 229`), matching the guard already used in Command. This also fixes Combobox, which shares the same input keydown handler.
5 changes: 4 additions & 1 deletion packages/bits-ui/src/lib/bits/select/select.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,10 @@ export class SelectInputState {
return;
}

if (e.key === kbd.ENTER && !e.isComposing) {
// `e.keyCode === 229` covers Safari + Japanese IME, where `isComposing` is not
// set while composing, so an IME-commit Enter would otherwise select an item.
// Mirrors the Enter guard in `command.svelte.ts`.
if (e.key === kbd.ENTER && !e.isComposing && e.keyCode !== 229) {
e.preventDefault();

const isCurrentSelectedValue =
Expand Down
25 changes: 25 additions & 0 deletions tests/src/tests/combobox/combobox.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,31 @@ describe("combobox - single", () => {
await expect.element(page.getByTestId("input")).toHaveValue("B");
});

it("should not select an item on enter while composing with an IME (keyCode 229)", async () => {
await openSingle();
await expect.element(page.getByTestId("input")).toHaveFocus();
await userEvent.keyboard(kbd.ARROW_DOWN);
await expect.element(page.getByTestId("2")).toHaveAttribute("data-highlighted");

// Safari + Japanese IME deliver the composition-commit Enter with `keyCode === 229`
// and `isComposing === false`, so it must not commit the highlighted item.
page.getByTestId("input").element().dispatchEvent(
new KeyboardEvent("keydown", {
key: "Enter",
keyCode: 229,
bubbles: true,
cancelable: true,
})
);
await tick();
await expect.element(page.getByTestId("content")).toBeVisible();
await expect.element(page.getByTestId("input")).not.toHaveValue("B");

// a normal Enter (keyCode 13, not composing) still commits the selection
await userEvent.keyboard(kbd.ENTER);
await expect.element(page.getByTestId("input")).toHaveValue("B");
});

it("should render an input if the `name` prop is passed", async () => {
const t = setupSingle();
await expect.element(t.getHiddenInput()).toBeInTheDocument();
Expand Down
Loading