mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
fix(Sidebar): scroll to top once the sidebar be closed.
This commit is contained in:
@@ -16,19 +16,42 @@ function SidebarContainer({
|
||||
// #withDashboard
|
||||
sidebarExpended,
|
||||
}) {
|
||||
const sidebarScrollerRef = React.useRef();
|
||||
|
||||
useEffect(() => {
|
||||
document.body.classList.toggle('has-mini-sidebar', !sidebarExpended);
|
||||
|
||||
if (!sidebarExpended && sidebarScrollerRef.current) {
|
||||
sidebarScrollerRef.current.scrollTo({
|
||||
top: 0,
|
||||
left: 0,
|
||||
});
|
||||
}
|
||||
}, [sidebarExpended]);
|
||||
|
||||
const handleSidebarMouseLeave = () => {
|
||||
if (!sidebarExpended && sidebarScrollerRef.current) {
|
||||
sidebarScrollerRef.current.scrollTo({ top: 0, left: 0, });
|
||||
}
|
||||
};
|
||||
|
||||
const scrollerElementRef = (ref) => {
|
||||
sidebarScrollerRef.current = ref;
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames('sidebar', {
|
||||
'sidebar--mini-sidebar': !sidebarExpended,
|
||||
})}
|
||||
id="sidebar"
|
||||
onMouseLeave={handleSidebarMouseLeave}
|
||||
>
|
||||
<div className={'sidebar__scroll-wrapper'}>
|
||||
<Scrollbar noDefaultStyles={true}>
|
||||
<Scrollbar
|
||||
noDefaultStyles={true}
|
||||
scrollerProps={{ elementRef: scrollerElementRef }}
|
||||
>
|
||||
<div className="sidebar__inner">{children}</div>
|
||||
</Scrollbar>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user