Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dialog close/cancel pointerdown -> click #1028

Merged
merged 2 commits into from
Dec 31, 2024
Merged
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/spotty-bottles-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

Dialog/Alert Dialog: change `Dialog.Close` and `AlertDialog.Cancel` events from `pointerdown` to `click`
25 changes: 0 additions & 25 deletions packages/bits-ui/src/lib/bits/dialog/dialog.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand All @@ -197,7 +186,6 @@ class DialogCloseState {
({
id: this.#id.current,
[this.#attr]: "",
onpointerdown: this.onpointerdown,
onclick: this.onclick,
onkeydown: this.onkeydown,
...this.#root.sharedProps,
Expand Down Expand Up @@ -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({
Expand All @@ -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) {
Expand All @@ -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,
Expand Down