Skip to content

Commit

Permalink
prevent pointerdown on items
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 19, 2024
1 parent a54bbe7 commit 311552d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/bits-ui/src/lib/bits/combobox/combobox.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sites/docs/src/lib/components/demos/combobox-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</script>

<Combobox.Root
type="single"
type="multiple"
name="favoriteFruit"
onOpenChange={(o) => {
if (!o) inputValue = "";
Expand Down

0 comments on commit 311552d

Please sign in to comment.