File tree Expand file tree Collapse file tree
__fixtures__/table-of-contents Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export type TableOfContentsItem = {
2424 isLoading ?: boolean ;
2525 isDisabled ?: boolean ;
2626 showSkeleton ?: boolean ;
27+ startExpanded ?: boolean ;
2728 action ?: {
2829 icon ?: FAIconProp ;
2930 name ?: string ;
@@ -105,7 +106,10 @@ function TableOfContentsInner<T extends TableOfContentsItem = TableOfContentsIte
105106 rowComponent : RowComponent = DefaultRow ,
106107 rowComponentExtraProps,
107108} : Pick < ITableOfContents < T , E > , 'className' | 'contents' | 'rowComponent' | 'rowComponentExtraProps' > ) {
108- const [ expanded , setExpanded ] = React . useState ( { } ) ;
109+ const [ expanded , setExpanded ] = React . useState ( ( ) => {
110+ const itemsToExpand = contents . filter ( item => item . startExpanded ) ;
111+ return Object . fromEntries ( itemsToExpand . map ( item => [ contents . indexOf ( item ) , true ] ) ) ;
112+ } ) ;
109113
110114 // an array of functions. Invoking the N-th function toggles the expanded flag on the N-th content item
111115 const toggleExpandedFunctions = React . useMemo ( ( ) => {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export const tree: ITableOfContentsLink[] = [
1212 type : 'group' ,
1313 to : '/path' ,
1414 icon : 'cloud' ,
15+ startExpanded : true ,
1516 } ,
1617 {
1718 name : 'Nested Item with text icon' ,
You can’t perform that action at this time.
0 commit comments