@ -75,22 +75,76 @@ export const ScrollWrapper = ({
|
|||||||
|
|
||||||
const [initialize, instance] = useOverlayScrollbars({
|
const [initialize, instance] = useOverlayScrollbars({
|
||||||
options: {
|
options: {
|
||||||
scrollbars: { autoHide: 'scroll' },
|
scrollbars: {
|
||||||
|
autoHide: 'scroll',
|
||||||
|
autoHideDelay: 500,
|
||||||
|
},
|
||||||
overflow: {
|
overflow: {
|
||||||
x: defaultEnableXScroll ? undefined : 'hidden',
|
x: defaultEnableXScroll ? 'scroll' : 'hidden',
|
||||||
y: defaultEnableYScroll ? undefined : 'hidden',
|
y: defaultEnableYScroll ? 'scroll' : 'hidden',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
scroll: handleScroll,
|
scroll: (osInstance) => {
|
||||||
|
const {
|
||||||
|
scrollOffsetElement: target,
|
||||||
|
scrollbarHorizontal,
|
||||||
|
scrollbarVertical,
|
||||||
|
} = osInstance.elements();
|
||||||
|
|
||||||
|
// Hide scrollbars by default
|
||||||
|
[scrollbarHorizontal, scrollbarVertical].forEach((scrollbar) => {
|
||||||
|
if (scrollbar !== null) {
|
||||||
|
scrollbar.track.style.visibility = 'hidden';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show appropriate scrollbar based on scroll direction
|
||||||
|
const isHorizontalScroll =
|
||||||
|
target.scrollLeft !== Number(target.dataset.lastScrollLeft || '0');
|
||||||
|
const isVerticalScroll =
|
||||||
|
target.scrollTop !== Number(target.dataset.lastScrollTop || '0');
|
||||||
|
|
||||||
|
// Show scrollbar based on scroll direction only with explicit conditions
|
||||||
|
if (
|
||||||
|
isHorizontalScroll === true &&
|
||||||
|
scrollbarHorizontal !== null &&
|
||||||
|
target.scrollWidth > target.clientWidth
|
||||||
|
) {
|
||||||
|
scrollbarHorizontal.track.style.visibility = 'visible';
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isVerticalScroll === true &&
|
||||||
|
scrollbarVertical !== null &&
|
||||||
|
target.scrollHeight > target.clientHeight
|
||||||
|
) {
|
||||||
|
scrollbarVertical.track.style.visibility = 'visible';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update scroll positions
|
||||||
|
target.dataset.lastScrollLeft = target.scrollLeft.toString();
|
||||||
|
target.dataset.lastScrollTop = target.scrollTop.toString();
|
||||||
|
|
||||||
|
handleScroll(osInstance);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (scrollableRef?.current !== null) {
|
const currentRef = scrollableRef.current;
|
||||||
initialize(scrollableRef.current);
|
|
||||||
|
if (currentRef !== null) {
|
||||||
|
initialize(currentRef);
|
||||||
}
|
}
|
||||||
}, [initialize, scrollableRef]);
|
|
||||||
|
return () => {
|
||||||
|
// Reset all component-specific Recoil state
|
||||||
|
setScrollTop(0);
|
||||||
|
setScrollLeft(0);
|
||||||
|
setOverlayScrollbars(null);
|
||||||
|
instance()?.destroy();
|
||||||
|
};
|
||||||
|
}, [initialize, instance, setScrollTop, setScrollLeft, setOverlayScrollbars]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOverlayScrollbars(instance());
|
setOverlayScrollbars(instance());
|
||||||
|
|||||||
Reference in New Issue
Block a user