Skip to content

Commit 33ca7c8

Browse files
committed
fix: isolate main page body from leftnav scroll-into-view behaviour
1 parent b7957b4 commit 33ca7c8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/Layout/LeftSidebar.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ const ChildAccordion = ({ content, tree }: { content: (NavProductPage | NavProdu
4646
useEffect(() => {
4747
if (activeTriggerRef.current) {
4848
setTimeout(() => {
49-
activeTriggerRef.current?.scrollIntoView({
50-
behavior: 'smooth',
51-
block: 'center',
52-
});
49+
const element = activeTriggerRef.current;
50+
const scrollableContainer = element?.closest('.overflow-y-auto');
51+
52+
if (element && scrollableContainer) {
53+
const elementRect = element.getBoundingClientRect();
54+
const containerRect = scrollableContainer.getBoundingClientRect();
55+
const scrollOffset = elementRect.top - containerRect.top - containerRect.height / 2 + elementRect.height / 2;
56+
57+
scrollableContainer.scrollBy({
58+
top: scrollOffset,
59+
behavior: 'smooth',
60+
});
61+
}
5362
}, 200);
5463
}
5564
}, [activePage.tree]);

0 commit comments

Comments
 (0)