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: closeOnOutsideClick & onOutsideClick behavior #27

Merged
merged 7 commits into from
Jan 13, 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/grumpy-gorillas-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vaul-svelte": patch
---

fix: `closeOnOutsideClick` & `onOutsideClick` behavior
2 changes: 1 addition & 1 deletion src/lib/internal/position-fixed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { onMount } from "svelte";
import { writable, get, type Writable } from "svelte/store";
import { effect, addEventListener } from "./helpers/index.js";
import { onMount } from "svelte";

let previousBodyPosition: Record<string, string> | null = null;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/internal/snap-points.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tick } from "svelte";
import { derived, get, type Writable } from "svelte/store";
import { TRANSITIONS, VELOCITY_THRESHOLD } from "./constants.js";
import { effect, set } from "./helpers/index.js";
import { tick } from "svelte";

export function handleSnapPoints({
activeSnapPoint,
Expand Down
7 changes: 7 additions & 0 deletions src/lib/vaul/components/root.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
export let fadeFromIndex: $$Props["fadeFromIndex"] = undefined;
export let openFocus: $$Props["openFocus"] = undefined;
export let onOutsideClick: $$Props["onOutsideClick"] = undefined;
export let closeOnOutsideClick: $$Props["closeOnOutsideClick"] = true;
export let nested: $$Props["nested"] = false;
export let shouldScaleBackground: $$Props["shouldScaleBackground"] = false;
export let activeSnapPoint: $$Props["activeSnapPoint"] = undefined;
Expand Down Expand Up @@ -77,6 +78,7 @@
</script>

<DialogPrimitive.Root
{closeOnOutsideClick}
closeOnEscape={false}
bind:open
preventScroll={false}
Expand All @@ -89,7 +91,12 @@
}
}}
onOutsideClick={(e) => {
if (!closeOnOutsideClick) return;

onOutsideClick?.(e);

if (e?.defaultPrevented) return;

if ($keyboardIsOpen) {
keyboardIsOpen.set(false);
}
Expand Down