|
Hi everyone! I'm using UNavigationMenu inside a sidebar (UDashboardSidebar) with custom styling provided via the :ui prop. I have nested items with children (e.g. Settings -> Staff, Billing, etc.). When a child menu item is selected/active, the child correctly receives active state styling (data-active), but the parent menu trigger item retains its default inactive styles. Here is an snippet of my navigation structure and setup: import type { NavigationMenuItem } from '@nuxt/ui'
const navigation = computed<NavigationMenuItem[]>(() => [
{
label: 'Dashboard',
icon: 'i-lucide-house',
to: '/app',
exact: true
},
{
label: 'Inventory',
icon: 'i-lucide-book-open',
to: '/app/inventory',
type: 'trigger',
children: [
{
label: 'Menu Items',
icon: 'i-lucide-utensils-crossed',
to: '/app/inventory',
exact: true
},
{
label: 'Item Modifiers',
icon: 'i-lucide-list-plus',
to: '/app/inventory/modifiers'
}
]
},
{
label: 'Settings',
icon: 'i-lucide-settings',
to: '/app/settings',
type: 'trigger',
children: [
{
label: 'General',
icon: 'i-lucide-user',
to: '/app/settings',
exact: true
},
{
label: 'Staff',
icon: 'i-lucide-users',
to: '/app/settings/staff'
}
]
}
])And my NavigationMenu <UNavigationMenu
:items="navigation"
:collapsed="collapsed"
tooltip
popover
orientation="vertical"
color="neutral"
:ui="{
childList: 'p-1.5 space-y-1',
list: collapsed ? 'flex flex-col items-center gap-1.5' : 'space-y-1.5',
link: [
'outline-none ring-0 border-0',
'before:hidden after:hidden',
'bg-white/5 border border-white/10 text-white/90',
'hover:bg-white/10 hover:text-white transition-all',
/* Target direct active item */
'data-[active=true]:bg-primary-500 data-[active=true]:text-white',
'h-11 rounded-lg',
collapsed ? 'justify-center px-0 w-11 mx-auto' : 'px-3.5'
].join(' '),
linkLeadingIcon: [
'shrink-0 size-5 text-white/80 group-hover:text-white',
'group-data-[active=true]:text-white'
].join(' ')
}"
/>Go easy on me, please. I am no CSS neither a Nuxt UI crack, gave my best but maybe the ui stylings are a bit messy. Thanks in advance everbody! |
Replies: 1 comment 1 reply
|
Your navigation structure is fine. Two separate things are stopping the styles from landing, and the first one is why it looks like the component "loses track" of the parent. 1.
|
Your navigation structure is fine. Two separate things are stopping the styles from landing, and the first one is why it looks like the component "loses track" of the parent.
1.
data-[active=true]never matchesThe attribute the component renders is valueless. From nuxt/ui's own render snapshot (
test/components/__snapshots__/NavigationMenu.spec.ts.snap, the collapsed vertical case, on an item declared withactive: true):It is
data-active="", notdata-active="true". Tailwind compilesdata-[active=true]:to[data-active="true"], which cannot match an empty value. So every one of thes…