From a4089ccd9b00c53b10551e4d7800f2b567376670 Mon Sep 17 00:00:00 2001 From: shadcn Date: Wed, 30 Oct 2024 20:01:14 +0400 Subject: [PATCH] fix: sidebar cookie handling --- components/ui/sidebar.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/components/ui/sidebar.tsx b/components/ui/sidebar.tsx index 6fd08de..1000e7f 100644 --- a/components/ui/sidebar.tsx +++ b/components/ui/sidebar.tsx @@ -81,16 +81,15 @@ const SidebarProvider = React.forwardRef< const open = openProp ?? _open; const setOpen = React.useCallback( (value: boolean | ((value: boolean) => boolean)) => { + const openState = typeof value === 'function' ? value(open) : value; if (setOpenProp) { - return setOpenProp?.( - typeof value === 'function' ? value(open) : value - ); + setOpenProp(openState); + } else { + _setOpen(openState); } - _setOpen(value); - // This sets the cookie to keep the sidebar state. - document.cookie = `${SIDEBAR_COOKIE_NAME}=${open}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`; + document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`; }, [setOpenProp, open] );