diff --git a/.changeset/spotty-bottles-battle.md b/.changeset/spotty-bottles-battle.md new file mode 100644 index 000000000..4c27c18c9 --- /dev/null +++ b/.changeset/spotty-bottles-battle.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +Dialog/Alert Dialog: change `Dialog.Close` and `AlertDialog.Cancel` events from `pointerdown` to `click` diff --git a/packages/bits-ui/src/lib/bits/dialog/dialog.svelte.ts b/packages/bits-ui/src/lib/bits/dialog/dialog.svelte.ts index c2cc205e9..9eb8ef23b 100644 --- a/packages/bits-ui/src/lib/bits/dialog/dialog.svelte.ts +++ b/packages/bits-ui/src/lib/bits/dialog/dialog.svelte.ts @@ -158,7 +158,6 @@ class DialogCloseState { this.#disabled = props.disabled; this.onclick = this.onclick.bind(this); - this.onpointerdown = this.onpointerdown.bind(this); this.onkeydown = this.onkeydown.bind(this); useRefById({ @@ -174,16 +173,6 @@ class DialogCloseState { this.#root.handleClose(); } - onpointerdown(e: BitsPointerEvent) { - if (this.#disabled.current) return; - if (e.button > 0) return; - // by default, it will attempt to focus this trigger on pointerdown - // since this also closes the dialog and restores focus we want to prevent that behavior - e.preventDefault(); - - this.#root.handleClose(); - } - onkeydown(e: BitsKeyboardEvent) { if (this.#disabled.current) return; if (e.key === kbd.SPACE || e.key === kbd.ENTER) { @@ -197,7 +186,6 @@ class DialogCloseState { ({ id: this.#id.current, [this.#attr]: "", - onpointerdown: this.onpointerdown, onclick: this.onclick, onkeydown: this.onkeydown, ...this.#root.sharedProps, @@ -399,7 +387,6 @@ class AlertDialogCancelState { this.#root = root; this.#disabled = props.disabled; this.onclick = this.onclick.bind(this); - this.onpointerdown = this.onpointerdown.bind(this); this.onkeydown = this.onkeydown.bind(this); useRefById({ @@ -418,17 +405,6 @@ class AlertDialogCancelState { this.#root.handleClose(); } - onpointerdown(e: BitsPointerEvent) { - if (this.#disabled.current) return; - if (e.pointerType === "touch") return e.preventDefault(); - if (e.button > 0) return; - // by default, it will attempt to focus this trigger on pointerdown - // since this also opens the dialog we want to prevent that behavior - e.preventDefault(); - - this.#root.handleClose(); - } - onkeydown(e: BitsKeyboardEvent) { if (this.#disabled.current) return; if (e.key === kbd.SPACE || e.key === kbd.ENTER) { @@ -442,7 +418,6 @@ class AlertDialogCancelState { ({ id: this.#id.current, [this.#root.attrs.cancel]: "", - onpointerdown: this.onpointerdown, onclick: this.onclick, onkeydown: this.onkeydown, ...this.#root.sharedProps,