Skip to content

Commit

Permalink
frontend: Sidebar: Resize sidebar when overflowing
Browse files Browse the repository at this point in the history
Signed-off-by: Evangelos Skopelitis <[email protected]>
  • Loading branch information
skoeva committed Dec 20, 2024
1 parent ac9fd90 commit 3e3b634
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
32 changes: 22 additions & 10 deletions frontend/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ export const PureSidebar = memo(
linkArea,
}: PureSidebarProps) => {
const { t } = useTranslation();
const listContainerRef = React.useRef<HTMLDivElement | null>(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).
Expand Down Expand Up @@ -276,6 +279,7 @@ export const PureSidebar = memo(
})}
/>
<Grid
ref={listContainerRef}
sx={{
height: '100%',
overflowY: 'auto',
Expand Down Expand Up @@ -337,6 +341,23 @@ export const PureSidebar = memo(
}
: {};

React.useEffect(() => {
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 (
<Box component="nav" aria-label={t('translation|Navigation')}>
<Drawer
Expand All @@ -363,16 +384,7 @@ export const PureSidebar = memo(
duration: theme.transitions.duration.leavingScreen,
}),
overflowX: 'hidden',
width: '56px',
[theme.breakpoints.down('xs')]: {
background: 'initial',
},
[theme.breakpoints.down('sm')]: {
width: theme.spacing(0),
},
[theme.breakpoints.up('sm')]: {
width: '72px',
},
width: `${adjustedDrawerWidthClosed}px`,
background: theme.palette.sidebarBg,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class="MuiBox-root css-0"
>
<div
class="MuiDrawer-root MuiDrawer-docked css-1p9jtjb-MuiDrawer-docked"
class="MuiDrawer-root MuiDrawer-docked css-1g0cdoa-MuiDrawer-docked"
>
<div
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class="MuiBox-root css-0"
>
<div
class="MuiDrawer-root MuiDrawer-docked css-1p9jtjb-MuiDrawer-docked"
class="MuiDrawer-root MuiDrawer-docked css-1g0cdoa-MuiDrawer-docked"
>
<div
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
Expand Down

0 comments on commit 3e3b634

Please sign in to comment.