How to customise the leading icon / avatar for UNavigationMenu Component
So I needed to customise how the UDashboardSidebar looks and this is what I'm using
This is to be an implementation of sidebar where the top level menu entries are persistently shown as icons in a coloured bar while the children menu entries are shown in the 2nd div (regular light mode or dark mode sidebar style)
in this style of menus usually the top level menu entry icons are fairly large (compared to regular size) I saw the code puts it as size-5 but there isn't really a prop or anything to adjust the sizes and figured i needed to override the #component-leading
Am i on the right track? how would i refer to the item (the navigationMenu gets passed an array via items prop) so something like item.icon can be referred to? would you recommend a different way?
2 Replies
Hi @SamKaizen. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
You're on the right track! The
- The documentation confirms the use of
UNavigationMenu
component supports custom slots for leading content, such as icons or avatars, for each item. To customize the leading icon/avatar and control its size, you should use the #item-leading
or #{{ item.slot }}-leading
slot. This gives you access to the current item, so you can render its icon or avatar as you wish.
Here's how you can do it:
1. Use the #item-leading
slot: This slot exposes the item
object, allowing you to access properties like item.icon
or item.avatar
.
2. Customize the icon size: You can apply any Tailwind class (e.g., size-7
, size-8
, etc.) to control the icon size.
Example
- item
is available in the slot scope, so you can reference item.icon
or item.avatar
directly.
- You can use any size class you want (size-8
, size-10
, etc.) to make the icons larger than the default.
This approach is recommended for your use case, as it gives you full control over the leading content for each menu item and allows you to adjust the size as needed for your sidebar design.
References:- The documentation confirms the use of
#item-leading
and other item slots for customization, and shows how to access the item
object within the slot scope. You can see an example of slot usage and item access here: With tooltip in items and With custom slot.
- The default icon size is set via classes like size-5
, but you can override this in your slot template as shown above NavigationMenu Theme.
Let me know if you need a more specific example or further customization!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@422361058246918146> Kapa.ai is still learning and improving, please let me know how I did by reacting below.