@@ -14,40 +14,47 @@ export function useAppLayout() {
1414 // Menu items
1515 const menuItems = computed < MenuItem [ ] > ( ( ) => [
1616 {
17+ key : 'home' ,
1718 label : 'Home' ,
1819 lucideIcon : House ,
1920 route : { name : 'welcome' } ,
2021 active : currentRoute . value == 'welcome' ,
2122 } ,
2223 {
24+ key : 'dashboard' ,
2325 label : 'Dashboard' ,
2426 lucideIcon : LayoutGrid ,
2527 route : { name : 'dashboard' } ,
2628 active : currentRoute . value == 'dashboard' ,
2729 } ,
2830 {
31+ key : 'resources' ,
2932 label : 'Resources' ,
3033 lucideIcon : Info ,
3134 items : [
3235 {
36+ key : 'resources-laravel' ,
3337 label : 'Laravel Docs' ,
3438 url : 'https://laravel.com/docs/master' ,
3539 target : '_blank' ,
3640 lucideIcon : ExternalLink ,
3741 } ,
3842 {
43+ key : 'resources-primevue' ,
3944 label : 'PrimeVue Docs' ,
4045 url : 'https://primevue.org/' ,
4146 target : '_blank' ,
4247 lucideIcon : ExternalLink ,
4348 } ,
4449 {
50+ key : 'resources-starter-docs' ,
4551 label : 'Starter Kit Docs' ,
4652 url : 'https://connorabbas.github.io/laravel-primevue-starter-kit-docs/' ,
4753 target : '_blank' ,
4854 lucideIcon : FileSearch ,
4955 } ,
5056 {
57+ key : 'resources-starter-repo' ,
5158 label : 'Starter Kit Repo' ,
5259 url : 'https://github.com/connorabbas/laravel-primevue-starter-kit' ,
5360 target : '_blank' ,
@@ -57,6 +64,25 @@ export function useAppLayout() {
5764 } ,
5865 ] )
5966
67+ // Check/set expanded PanelMenu items based on active status, for non-persistent layouts & page refreshes
68+ const expandedKeys = ref < Record < string , boolean > > ( { } )
69+ const updateExpandedKeys = ( ) => {
70+ const keys : Record < string , boolean > = { }
71+ const hasActiveChild = ( item : MenuItem ) : boolean => {
72+ if ( item . items ) {
73+ for ( const child of item . items ) {
74+ if ( hasActiveChild ( child ) ) {
75+ if ( item . key ) keys [ item . key ] = true
76+ return true
77+ }
78+ }
79+ }
80+ return ! ! item . active
81+ }
82+ menuItems . value . forEach ( hasActiveChild )
83+ expandedKeys . value = keys
84+ }
85+
6086 // User menu and logout functionality.
6187 const userMenuItems : MenuItem [ ] = [
6288 {
@@ -81,6 +107,7 @@ export function useAppLayout() {
81107 windowWidth . value = window . innerWidth
82108 }
83109 onMounted ( ( ) => {
110+ updateExpandedKeys ( )
84111 window . addEventListener ( 'resize' , updateWidth )
85112 } )
86113 onUnmounted ( ( ) => {
@@ -96,6 +123,7 @@ export function useAppLayout() {
96123 userName,
97124 currentRoute,
98125 menuItems,
126+ expandedKeys,
99127 userMenuItems,
100128 mobileMenuOpen,
101129 }
0 commit comments