Skip to content

Commit

Permalink
next: fix command click event handling (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Oct 26, 2024
1 parent a7b094b commit 7a9ea27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-bags-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: command click events
16 changes: 3 additions & 13 deletions packages/bits-ui/src/lib/bits/command/command.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class CommandRootState {
const grandparent = item.parentElement?.parentElement;
if (!grandparent) return;
const firstChildOfParent = getFirstNonCommentChild(grandparent) as HTMLElement | null;
if (firstChildOfParent && firstChildOfParent.dataset.value === item.dataset.value) {
if (firstChildOfParent && firstChildOfParent.dataset?.value === item.dataset?.value) {
item
?.closest(GROUP_SELECTOR)
?.querySelector(GROUP_HEADING_SELECTOR)
Expand Down Expand Up @@ -877,20 +877,11 @@ class CommandItemState {
this.#select();
};

#onpointerdown = (e: PointerEvent) => {
#onclick = () => {
if (this.#disabled.current) return;
if (e.pointerType === "touch" || e.button !== 0) return e.preventDefault();
this.#onSelect();
};

#onpointerup = (e: PointerEvent) => {
if (this.#disabled.current) return;
if (e.pointerType === "touch") {
e.preventDefault();
this.#onSelect();
}
};

props = $derived.by(
() =>
({
Expand All @@ -901,9 +892,8 @@ class CommandItemState {
"data-selected": getDataSelected(this.isSelected),
[ITEM_ATTR]: "",
role: "option",
onpointerdown: this.#onpointerdown,
onpointermove: this.#onpointermove,
onpointerup: this.#onpointerup,
onclick: this.#onclick,
}) as const
);
}
Expand Down

0 comments on commit 7a9ea27

Please sign in to comment.