File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff 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 ] ) ;
You can’t perform that action at this time.
0 commit comments