fix(Sidebar): scroll to top once the sidebar be closed.

This commit is contained in:
a.bouhuolia
2021-03-21 13:38:10 +02:00
parent 81621020c2
commit 0f1c88cba3
5 changed files with 43 additions and 20 deletions

View File

@@ -16,19 +16,42 @@ function SidebarContainer({
// #withDashboard // #withDashboard
sidebarExpended, sidebarExpended,
}) { }) {
const sidebarScrollerRef = React.useRef();
useEffect(() => { useEffect(() => {
document.body.classList.toggle('has-mini-sidebar', !sidebarExpended); document.body.classList.toggle('has-mini-sidebar', !sidebarExpended);
if (!sidebarExpended && sidebarScrollerRef.current) {
sidebarScrollerRef.current.scrollTo({
top: 0,
left: 0,
});
}
}, [sidebarExpended]); }, [sidebarExpended]);
const handleSidebarMouseLeave = () => {
if (!sidebarExpended && sidebarScrollerRef.current) {
sidebarScrollerRef.current.scrollTo({ top: 0, left: 0, });
}
};
const scrollerElementRef = (ref) => {
sidebarScrollerRef.current = ref;
};
return ( return (
<div <div
className={classNames('sidebar', { className={classNames('sidebar', {
'sidebar--mini-sidebar': !sidebarExpended, 'sidebar--mini-sidebar': !sidebarExpended,
})} })}
id="sidebar" id="sidebar"
onMouseLeave={handleSidebarMouseLeave}
> >
<div className={'sidebar__scroll-wrapper'}> <div className={'sidebar__scroll-wrapper'}>
<Scrollbar noDefaultStyles={true}> <Scrollbar
noDefaultStyles={true}
scrollerProps={{ elementRef: scrollerElementRef }}
>
<div className="sidebar__inner">{children}</div> <div className="sidebar__inner">{children}</div>
</Scrollbar> </Scrollbar>
</div> </div>

View File

@@ -2,7 +2,6 @@ import React, { useState, createContext } from 'react';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import DashboardInsider from 'components/Dashboard/DashboardInsider'; import DashboardInsider from 'components/Dashboard/DashboardInsider';
import { import {
useCustomers,
useCustomer, useCustomer,
useCurrencies, useCurrencies,
useCreateCustomer, useCreateCustomer,
@@ -18,22 +17,17 @@ function CustomerFormProvider({ customerId, ...props }) {
const contactId = state?.action; const contactId = state?.action;
// Handle fetch customer details. // Handle fetch customer details.
const { data: customer, isFetching: isCustomerLoading } = useCustomer( const { data: customer, isLoading: isCustomerLoading } = useCustomer(
customerId, customerId,
{ { enabled: !!customerId },
enabled: !!customerId,
},
); );
// Handle fetch contact duplicate details. // Handle fetch contact duplicate details.
const { data: contactDuplicate, isFetching: isContactLoading } = useContact( const { data: contactDuplicate, isLoading: isContactLoading } = useContact(
contactId, contactId,
{ { enabled: !!contactId, },
enabled: !!contactId,
},
); );
// Handle fetch Currencies data table // Handle fetch Currencies data table
const { data: currencies, isFetching: isCurrenciesLoading } = useCurrencies(); const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
// Form submit payload. // Form submit payload.
const [submitPayload, setSubmitPayload] = useState({}); const [submitPayload, setSubmitPayload] = useState({});

View File

@@ -29,7 +29,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
// Fetches the estimate by the given id. // Fetches the estimate by the given id.
const { const {
data: estimate, data: estimate,
isFetching: isEstimateFetching, isLoading: isEstimateLoading,
} = useEstimate(estimateId, { enabled: !!estimateId }); } = useEstimate(estimateId, { enabled: !!estimateId });
const newInvoice = !isEmpty(estimate) const newInvoice = !isEmpty(estimate)
@@ -97,7 +97,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
isInvoiceLoading || isInvoiceLoading ||
isItemsLoading || isItemsLoading ||
isCustomersLoading || isCustomersLoading ||
isEstimateFetching || isEstimateLoading ||
isSettingsLoading isSettingsLoading
} }
name={'invoice-form'} name={'invoice-form'}

View File

@@ -20,21 +20,19 @@ function VendorFormProvider({ vendorId, ...props }) {
const { state } = useLocation(); const { state } = useLocation();
// Handle fetch Currencies data table // Handle fetch Currencies data table
const { data: currencies, isFetching: isCurrenciesLoading } = useCurrencies(); const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
// Handle fetch vendor details. // Handle fetch vendor details.
const { data: vendor, isFetching: isVendorLoading } = useVendor(vendorId, { const { data: vendor, isLoading: isVendorLoading } = useVendor(vendorId, {
enabled: !!vendorId, enabled: !!vendorId,
}); });
const contactId = state?.action; const contactId = state?.action;
// Handle fetch contact duplicate details. // Handle fetch contact duplicate details.
const { data: contactDuplicate, isFetching: isContactLoading } = useContact( const { data: contactDuplicate, isLoading: isContactLoading } = useContact(
contactId, contactId,
{ { enabled: !!contactId },
enabled: !!contactId,
},
); );
// Create and edit vendor mutations. // Create and edit vendor mutations.

View File

@@ -237,6 +237,10 @@
transition: min-width 0.15s ease-in-out; transition: min-width 0.15s ease-in-out;
min-width: 50px; min-width: 50px;
.ScrollbarsCustom-Scroller{
overflow: hidden !important;
}
&:hover { &:hover {
min-width: 220px; min-width: 220px;
@@ -251,6 +255,10 @@
.sidebar__menu { .sidebar__menu {
opacity: 1; opacity: 1;
} }
.ScrollbarsCustom-Scroller{
overflow: scroll !important;
}
} }
} }
} }