Skip to content

Targeting active menu styles #4279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
idesignpixels opened this issue Jun 2, 2025 · 1 comment
Open

Targeting active menu styles #4279

idesignpixels opened this issue Jun 2, 2025 · 1 comment
Labels
question Further information is requested v3 #1289

Comments

@idesignpixels
Copy link

Description

No Clear Documentation for Targeting Active Styles in NavigationMenu Component

Description

I'm trying to apply custom styles to the active state of a menu item in the NavigationMenu component, but there doesn't seem to be any clear documentation on how to do this.

The theming docs mention using the :ui attribute to target internal parts of a component, and the theme structure for NavigationMenu shows a large theme object. However, attempting to follow that structure often results in unexpected behavior—like rendering [object Object], which suggests that it doesn't expect an object or the nested configuration isn’t being parsed correctly.

Even large language models get tripped up when referencing the documentation. Some approaches I've tried (unsuccessfully) include:

link: {
  base: 'px-3 py-2 rounded-md',
  active: 'bg-primary text-white font-medium'
},
variants: {
  active: {
    true: {
      item: 'bg-primary text-white font-medium'
    }
  }
}

The only working solution so far is using data-* attributes like this:

link: 'text-md data-active:bg-primary data-active:text-white'

While this works, it’s undocumented and feels fragile—it could easily break with a future update if it’s not the intended method.

Question

What is the official and supported way to apply styles based on active state for subcomponents like link in NavigationMenu?

@idesignpixels idesignpixels added question Further information is requested v3 #1289 labels Jun 2, 2025
@alexandrekabolt
Copy link

I have the same issue on the project i'm working and still not found a clear solution.

I tried something similar with hover effects in addition but now I have some white flicker issue when hovering because of the bg-elevated & transition-colors classes

here's what I'm using

link: 'data-active:bg-gray-700 data-active:before:bg-gray-700 rounded-lg before:rounded-lg hover:bg-gray-700 hover:before:bg-gray-700',
Capture.video.2025-06-06.11.02.14.mp4

I'm migrating from Nuxt UI V2 to Nuxt UI V3 and theses complications with theme customization gives me the impression of regression at this state.

I would like to know if there's a better solution for doing this because I'm feeling like it's just me not doing the right thing but I can't figure out how to do it from the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested v3 #1289
Projects
None yet
Development

No branches or pull requests

2 participants