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

  1. 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>
  1. 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>
  1. 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

Most upvoted comments

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:

<SidebarMenuButton 
  asChild 
  size="lg" 
  className="[&>svg]:size-6 group-data-[collapsible=icon]:[&>svg]:ml-1"
/>

The class [&>svg]:size-6 adjusts the icon size accordingly, and group-data-[collapsible=icon]:[&>svg]:ml-1 handles 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 Screenshot_23-10-2024_154010_localhost

Expanded state: image

I fix the problem for the lg size by adding this class group-data-[collapsible=icon]:[&>svg]:ml-2 to sidebarMenuButtonVariants in sidebar.tsx

image

@ledevmacedo @Timmy0o0 @anmoroz
I did some tinkering on the sidebar.tsx and 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 want

carbon

Then i used the Avatar component in a brute way to render the image carbon

Also notice the changes to the className of the SidebarMenuButton component, which I added for preference, so i have the open and close states like these: Screenshot_29-10-2024_121025_localhost

Screenshot_29-10-2024_121043_localhost

@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 Button and DropdownMenu components from shadcn and reload.