From dc50e7b983a5e554aead80af97141f591f54f67c Mon Sep 17 00:00:00 2001 From: Evangelos Skopelitis Date: Fri, 20 Dec 2024 16:12:10 -0500 Subject: [PATCH] frontend: Sidebar: Resize sidebar when overflowing Signed-off-by: Evangelos Skopelitis --- frontend/src/components/Sidebar/Sidebar.tsx | 32 +++++++++++++------ ...idebar.HomeSidebarClosed.stories.storyshot | 2 +- ...r.InClusterSidebarClosed.stories.storyshot | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/Sidebar/Sidebar.tsx b/frontend/src/components/Sidebar/Sidebar.tsx index eb49452918..8f1552e469 100644 --- a/frontend/src/components/Sidebar/Sidebar.tsx +++ b/frontend/src/components/Sidebar/Sidebar.tsx @@ -275,6 +275,9 @@ export const PureSidebar = memo( linkArea, }: PureSidebarProps) => { const { t } = useTranslation(); + const listContainerRef = React.useRef(null); + const [isOverflowing, setIsOverflowing] = React.useState(false); + const adjustedDrawerWidthClosed = isOverflowing ? 84 : 72; const temporarySideBarOpen = open === true && isTemporaryDrawer && openUserSelected === true; // The large sidebar does not open in medium view (600-960px). @@ -303,6 +306,7 @@ export const PureSidebar = memo( })} /> { + const el = listContainerRef.current; + if (!el) { + return; + } + + const observer = new ResizeObserver(() => { + setIsOverflowing(el.scrollHeight > el.clientHeight); + }); + + observer.observe(el); + + setIsOverflowing(el.scrollHeight > el.clientHeight); + + return () => observer.disconnect(); + }, [items]); + return (