From b607a9a76e80d5066ac72852f0056ac41502a04d Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Tue, 24 Mar 2026 22:11:46 +0100 Subject: [PATCH] fix: site picker opens outside sidebar when collapsed No longer expands sidebar first. When collapsed, dropdown appears to the right of the button (like AppLauncher/UserMenu/Notifications). When expanded, opens below the button. --- components/dashboard/Sidebar.tsx | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/components/dashboard/Sidebar.tsx b/components/dashboard/Sidebar.tsx index 696b158..33b8b70 100644 --- a/components/dashboard/Sidebar.tsx +++ b/components/dashboard/Sidebar.tsx @@ -136,14 +136,25 @@ function SitePicker({ sites, siteId, collapsed, onExpand, onCollapse, wasCollaps const updatePosition = useCallback(() => { if (buttonRef.current) { const rect = buttonRef.current.getBoundingClientRect() - let top = rect.bottom + 4 - if (panelRef.current) { - const maxTop = window.innerHeight - panelRef.current.offsetHeight - 8 - top = Math.min(top, Math.max(8, maxTop)) + if (collapsed) { + // Collapsed: open to the right, like AppLauncher/UserMenu/Notifications + let top = rect.top + if (panelRef.current) { + const maxTop = window.innerHeight - panelRef.current.offsetHeight - 8 + top = Math.min(top, Math.max(8, maxTop)) + } + setFixedPos({ left: rect.right + 8, top }) + } else { + // Expanded: open below the button + let top = rect.bottom + 4 + if (panelRef.current) { + const maxTop = window.innerHeight - panelRef.current.offsetHeight - 8 + top = Math.min(top, Math.max(8, maxTop)) + } + setFixedPos({ left: rect.left, top }) } - setFixedPos({ left: rect.left, top }) } - }, []) + }, [collapsed]) useEffect(() => { const handler = (e: MouseEvent) => { @@ -154,7 +165,6 @@ function SitePicker({ sites, siteId, collapsed, onExpand, onCollapse, wasCollaps ) { if (open) { setOpen(false); setSearch('') - if (wasCollapsed.current) { onCollapse(); wasCollapsed.current = false } } } } @@ -171,7 +181,6 @@ function SitePicker({ sites, siteId, collapsed, onExpand, onCollapse, wasCollaps const closePicker = () => { setOpen(false); setSearch('') - if (wasCollapsed.current) { onCollapse(); wasCollapsed.current = false } } const switchSite = (id: string) => { @@ -247,15 +256,7 @@ function SitePicker({ sites, siteId, collapsed, onExpand, onCollapse, wasCollaps