From 311552d8d9f2d146eff354fd9ff5361fefbdae66 Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Fri, 19 Jul 2024 17:56:14 -0400 Subject: [PATCH] prevent pointerdown on items --- packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts | 6 ++++++ sites/docs/src/lib/components/demos/combobox-demo.svelte | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts b/packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts index a172c2a29..8b97a2f58 100644 --- a/packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts +++ b/packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts @@ -522,6 +522,11 @@ class ComboboxItemState { highlighted: this.isHighlighted, })); + #onpointerdown = (e: PointerEvent) => { + // prevent focus from leaving the combobox + e.preventDefault(); + }; + /** * Using `pointerup` instead of `click` allows power users to pointerdown * the trigger, then release pointerup on an item to select it vs having to do @@ -560,6 +565,7 @@ class ComboboxItemState { "data-label": this.label.value, [COMBOBOX_ITEM_ATTR]: "", onpointermove: this.#onpointermove, + onpointerdown: this.#onpointerdown, onpointerleave: this.#onpointerleave, onpointerup: this.#onpointerup, }) as const diff --git a/sites/docs/src/lib/components/demos/combobox-demo.svelte b/sites/docs/src/lib/components/demos/combobox-demo.svelte index 4a5346571..248644302 100644 --- a/sites/docs/src/lib/components/demos/combobox-demo.svelte +++ b/sites/docs/src/lib/components/demos/combobox-demo.svelte @@ -20,7 +20,7 @@ { if (!o) inputValue = "";