From 2565ae78b9c963c36a53c29296f711ede95bfa5f Mon Sep 17 00:00:00 2001 From: thedivtagguy Date: Mon, 4 Nov 2024 12:17:01 +0530 Subject: [PATCH] fix: added type check for currentId --- src/lib/vaul/components/root.svelte | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/vaul/components/root.svelte b/src/lib/vaul/components/root.svelte index a0f78eb..82ca28e 100644 --- a/src/lib/vaul/components/root.svelte +++ b/src/lib/vaul/components/root.svelte @@ -122,12 +122,14 @@ const $openDialogIds = get(openDrawerIds); const currentId = get(drawerId); - // Find the index of the current drawer - const currentIndex = $openDialogIds.indexOf(currentId); - // Only close if this is the topmost drawer - if (currentIndex === $openDialogIds.length - 1) { - onOpenChange?.(false); - closeDrawer(); + if (currentId) { + // Find the index of the current drawer + const currentIndex = $openDialogIds.indexOf(currentId); + // Only close if this is the topmost drawer + if (currentIndex === $openDialogIds.length - 1) { + onOpenChange?.(false); + closeDrawer(); + } } }} {...$$restProps}