ui: [bug]: Sidebar icon size is not taken in consideration
Describe the bug
When I set the size=lg to the <SidebarMenuButton>component, only the spacing between rows is updated.
By default, Icons have a size of 16px. In my case, i’m looking for bigger icons like 20 or 24px.
The size=lgdoes not work as expected.
Affected component/components
Sidebar
How to reproduce
- relay on the default icon size:
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<a href={item.url}>
<item.icon width="8" height="8" />
<span>{item.title}</span>
</a>
</SidebarMenuButton>
- update the size of each SidebarMenuItem:
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild size="lg">
<a href={item.url}>
<item.icon width="8" height="8" />
<span>{item.title}</span>
</a>
</SidebarMenuButton>
- Analyse the difference
The icon size are the same
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
macOS 15.0.1
Latest Chrome
NextJS 14
latest Shadcn
Before submitting
- I’ve made research efforts and searched the documentation
- I’ve searched for existing issues
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 15
- Comments: 21
Just in case these previous solutions don’t work for someone, what worked for me was overriding the svg size for the <SidebarMenuButton> in the className, like so:
<SidebarMenuButton className='[&>svg]:size-6'> ... </SidebarMenuButton>This changed the icon to the desired size, and then I made other adjustments to fit them in a way that worked for me. Hope it helps someone! 😃
Here’s the snippet that worked for me:
The class
[&>svg]:size-6adjusts the icon size accordingly, andgroup-data-[collapsible=icon]:[&>svg]:ml-1handles the left margin for collapsible icons.Hope this helps someone out!
I am also experiencing this issue where i would like to have my collapsed icon bigger, but the button restricts it and even shows a blank area
Collapsed State
Expanded state:
I fix the problem for the
lgsize by adding this classgroup-data-[collapsible=icon]:[&>svg]:ml-2tosidebarMenuButtonVariantsinsidebar.tsx@ledevmacedo @Timmy0o0 @anmoroz
I did some tinkering on the
sidebar.tsxand I was able to hard set the size of the collapsed icon state. The part in purple was part of my change, so it sets the collapsed size to the exact size I wantThen i used the
Avatarcomponent in a brute way to render the imageAlso notice the changes to the className of the
SidebarMenuButtoncomponent, which I added for preference, so i have the open and close states like these:@hypegg thanks for the solution
fk shadcn yall go take off the button and replace the onClick or whateever properties onto the icon itself
Is an action is scheduled to upgrade this component to let users managed icon sizes without hacks?
Make sure you have the latest
ButtonandDropdownMenucomponents from shadcn and reload.