Skip to content

Commit

Permalink
fix: closeOnOutsideClick & onOutsideClick behavior (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
neimadt committed Jan 13, 2024
1 parent 345a35f commit f9f477e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
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

0 comments on commit f9f477e

Please sign in to comment.