From 0f1c88cba383789ba292c981f41ebd5ac900c2d9 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sun, 21 Mar 2021 13:38:10 +0200 Subject: [PATCH] fix(Sidebar): scroll to top once the sidebar be closed. --- .../components/Sidebar/SidebarContainer.js | 25 ++++++++++++++++++- .../CustomerForm/CustomerFormProvider.js | 16 ++++-------- .../InvoiceForm/InvoiceFormProvider.js | 4 +-- .../Vendors/VendorForm/VendorFormProvider.js | 10 +++----- .../style/containers/Dashboard/Sidebar.scss | 8 ++++++ 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/client/src/components/Sidebar/SidebarContainer.js b/client/src/components/Sidebar/SidebarContainer.js index d8f4ab5c9..13b1b4a09 100644 --- a/client/src/components/Sidebar/SidebarContainer.js +++ b/client/src/components/Sidebar/SidebarContainer.js @@ -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 (