11import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
22import classNames from "classnames" ;
3- import { ComponentType , useState } from "react" ;
3+ import { ComponentType , useState , useRef , useEffect } from "react" ;
44import { Collapse , NavItem } from "reactstrap" ;
55import { LinkRendererProps } from "src/lib/SideBar/SideBarMenuContext" ;
66import { PanelItem } from "./../PanelSideBar/Definitions/PanelItem" ;
@@ -19,52 +19,62 @@ const PanelSideBarItem = (props: PanelSideBarItemProps) => {
1919 const { depth = 0 , children : item , LinkRenderer, onClick, toggledItemIds = [ ] , toggledSidebar } = props ;
2020
2121 const hasitem = ! ! item . children ?. length ;
22+ const isActive = item . children ?. find ( ( s ) => s . active ) || item . active ;
2223 const [ isOpen , setIsOpen ] = useState ( toggledItemIds ?. includes ( item . id ) || item . expanded ) ;
2324 if ( item . display === false ) {
2425 return null ;
2526 }
27+ const scrollToActiveItemRef = useRef < HTMLDivElement > ( null ) ;
28+
29+ useEffect ( ( ) => {
30+ if ( scrollToActiveItemRef . current && isActive ) {
31+ scrollToActiveItemRef . current . scrollIntoView ( ) ;
32+ }
33+ } , [ ] ) ;
2634
2735 return (
2836 < >
2937 < NavItem
3038 onClick = { ( ) => onClick && onClick ( item ) }
31- className = { classNames ( { "menu-open" : isOpen , active : item . children ?. find ( ( s ) => s . active ) || item . active } ) }
39+ className = { classNames ( { "menu-open" : isOpen , active : isActive } ) }
3240 style = { { paddingLeft : depth ? `${ depth + 1 } rem` : undefined } }
3341 >
34- { hasitem ? (
35- < div className = { classNames ( "d-flex flex-row" , { "justify-content-between" : item . collapseIconOnly } ) } >
36- { item . collapseIconOnly && (
42+ < div ref = { scrollToActiveItemRef } >
43+ { hasitem ? (
44+ < div className = { classNames ( "d-flex flex-row" , { "justify-content-between" : item . collapseIconOnly } ) } >
45+ { item . collapseIconOnly && (
46+ < LinkRenderer item = { item } >
47+ < span className = "nav-link" >
48+ { item . icon && < FontAwesomeIcon icon = { item . icon } className = "me-2" /> }
49+ { item . title }
50+ </ span >
51+ </ LinkRenderer >
52+ ) }
53+
54+ < a
55+ role = "button"
56+ className = { classNames ( "nav-link" , { "w-100" : ! item . collapseIconOnly } , { "dropdown-toggle" : hasitem } ) }
57+ onClick = { ( ) => setIsOpen ( ! isOpen ) }
58+ >
59+ { ! item . collapseIconOnly && (
60+ < span >
61+ { item . icon && < FontAwesomeIcon className = "me-2" icon = { item . icon } /> }
62+ { item . title }
63+ </ span >
64+ ) }
65+ </ a >
66+ </ div >
67+ ) : (
68+ < >
3769 < LinkRenderer item = { item } >
3870 < span className = "nav-link" >
3971 { item . icon && < FontAwesomeIcon icon = { item . icon } className = "me-2" /> }
4072 { item . title }
4173 </ span >
4274 </ LinkRenderer >
43- ) }
44-
45- < a
46- role = "button"
47- className = { classNames ( "nav-link" , { "w-100" : ! item . collapseIconOnly } , { "dropdown-toggle" : hasitem } ) }
48- onClick = { ( ) => setIsOpen ( ! isOpen ) }
49- >
50- { ! item . collapseIconOnly && (
51- < span >
52- { item . icon && < FontAwesomeIcon className = "me-2" icon = { item . icon } /> }
53- { item . title }
54- </ span >
55- ) }
56- </ a >
57- </ div >
58- ) : (
59- < >
60- < LinkRenderer item = { item } >
61- < span className = "nav-link" >
62- { item . icon && < FontAwesomeIcon icon = { item . icon } className = "me-2" /> }
63- { item . title }
64- </ span >
65- </ LinkRenderer >
66- </ >
67- ) }
75+ </ >
76+ ) }
77+ </ div >
6878 </ NavItem >
6979
7080 { hasitem && (
0 commit comments