Skip to content

Commit d9d6788

Browse files
authored
Merge pull request #59 from connorabbas/develop
More fixes from inertia project
2 parents 35019c3 + c7afbf4 commit d9d6788

File tree

8 files changed

+38
-4
lines changed

8 files changed

+38
-4
lines changed

src/assets/css/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ body {
1717
.lucide {
1818
width: 16px;
1919
height: 16px;
20+
flex-shrink: 0;
2021
}

src/components/router-link-menus/Breadcrumb.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defineExpose({ $el: childRef })
2222
<template>
2323
<Breadcrumb
2424
ref="child-ref"
25-
v-bind="{ ...componentProps, pt: defaultPt, ptOptions: { mergeProps: ptViewMerge } }"
25+
v-bind="{ ...componentProps, ...$attrs, pt: defaultPt, ptOptions: { mergeProps: ptViewMerge } }"
2626
>
2727
<template #item="{ item, props }">
2828
<RouterLink

src/components/router-link-menus/Menu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defineExpose({
2121
<template>
2222
<Menu
2323
ref="child-ref"
24-
v-bind="{ ...componentProps, ptOptions: { mergeProps: ptViewMerge } }"
24+
v-bind="{ ...componentProps, ...$attrs, ptOptions: { mergeProps: ptViewMerge } }"
2525
>
2626
<template
2727
v-for="(_, slotName) in $slots"

src/components/router-link-menus/MenuBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defineExpose({ $el: childRef })
2222
<template>
2323
<Menubar
2424
ref="child-ref"
25-
v-bind="{ ...componentProps, ptOptions: { mergeProps: ptViewMerge } }"
25+
v-bind="{ ...componentProps, ...$attrs, ptOptions: { mergeProps: ptViewMerge } }"
2626
>
2727
<template
2828
v-for="(_, slotName) in $slots"

src/components/router-link-menus/PanelMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defineExpose({ $el: childRef })
2525
<template>
2626
<PanelMenu
2727
ref="child-ref"
28-
v-bind="{ ...componentProps, pt: defaultPt, ptOptions: { mergeProps: ptViewMerge } }"
28+
v-bind="{ ...componentProps, ...$attrs, pt: defaultPt, ptOptions: { mergeProps: ptViewMerge } }"
2929
>
3030
<template #item="{ item, root, active, props, hasSubmenu }">
3131
<Divider

src/composables/useAppLayout.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/layouts/app/HeaderLayout.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
currentRoute,
2121
mobileMenuOpen,
2222
menuItems,
23+
expandedKeys,
2324
userMenuItems,
2425
} = useAppLayout()
2526
</script>
@@ -34,6 +35,7 @@ const {
3435
>
3536
<div>
3637
<PanelMenu
38+
v-model:expandedKeys="expandedKeys"
3739
:model="menuItems"
3840
class="mt-1 w-full"
3941
/>

src/layouts/app/SidebarLayout.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
userName,
1919
mobileMenuOpen,
2020
menuItems,
21+
expandedKeys,
2122
userMenuItems,
2223
} = useAppLayout()
2324
</script>
@@ -32,6 +33,7 @@ const {
3233
>
3334
<div>
3435
<PanelMenu
36+
v-model:expandedKeys="expandedKeys"
3537
:model="menuItems"
3638
class="mt-1 w-full"
3739
/>
@@ -91,6 +93,7 @@ const {
9193
</div>
9294
<div>
9395
<PanelMenu
96+
v-model:expandedKeys="expandedKeys"
9497
:model="menuItems"
9598
class="mt-1 w-full"
9699
/>

0 commit comments

Comments
 (0)