ui: [bug]: Main content for Sidebar width expands to content and scrolls horizontally

Describe the bug

I’m trying out the Sidebar implementation, but I’m running into an issue where the “main” content’s width expands to fit the content, which doesn’t seem like a sensible default.

For example, if I make a sidebar-01 & add a data table with lots of columns, the main content will expand to fit the size of the table so that the main content of the sidebar becomes horizontally scrollable, which is almost never expected, unless you’re building some kind of infinite canvas type of application.

Would be great if this could be considered for a bug fix

Affected component/components

Sidebar

How to reproduce

  1. Check out sidebar-01 in v0
  2. Add a very wide Table component into the main content so that it will exceed the available width
Screenshot 2024-10-24 at 15 13 26 Screenshot 2024-10-24 at 15 13 36

Codesandbox/StackBlitz link

https://v0.dev/chat/petY7aNQAYx?b=b_GgHLxNdMNlr

Logs

No response

System Info

N/A

Before submitting

  • I’ve made research efforts and searched the documentation
  • I’ve searched for existing issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 16

Commits related to this issue

Most upvoted comments

In my case adding className="overflow-hidden" to SidebarInset solved the problem.

@kchro3 codesandbox link (fork): https://v0.dev/chat/K1ebiVKWPDV?b=JzbbCb0GaQc

Code snippet of the layout with header and sidebar:

return (
  <SidebarProvider>
    <AppSidebar />
    <SidebarInset className="overflow-hidden">
      <Header />
      <div className="flex-1 flex flex-col mx-auto p-6 w-full">{children}</div>
    </SidebarInset>
  </SidebarProvider>
);

I’ve used <SidebarInset className="min-w-0" /> and it resolved the layout issue for me.

<SidebarProvider>
  <AppSidebar />
  <SidebarInset className="min-w-0">
    ...
  </SidebarInset>
</SidebarProvider>

This approach doesn’t break any sticky elements inside, unlike setting overflow-hidden, which can interfere with sticky positioning.

Adding max-w-full class in SidebarInset fixes the problem for me

<SidebarInset className="max-w-full">
    ....
</SidebarInset>

after reading some comments here, i’ve found a tricky solution that fix the sticky header and overflow table by using sidebar hooks and fixed position.

On the layout.tsx use overflow-auto :

<SidebarProvider>
                <AppSidebar />
                <SidebarInset className="overflow-auto">
                    <Header />

                    <div className="flex-1 flex flex-col mx-auto p-6 w-full">
                        <Outlet />
                    </div>
                </SidebarInset>
 </SidebarProvider>

On the header.tsx use fixed instead of sticky and use sidebar hooks and cn:

const { isMobile, state } = useSidebar();

return (
<header className={cn(
            "fixed z-10 border-b bg-opacity-30 backdrop-blur-lg backdrop-filter transition-all",
            {
                "w-full": isMobile,
                "w-[calc(100%-var(--sidebar-width))]": !isMobile && state === "expanded",
                "w-[calc(100%-var(--sidebar-width-icon))]": !isMobile && state === "collapsed",
            }
        )}>
)

Yea i need to calculate the width 100% - sidebar width for expanded and 100% - sidebar width icon for collapsed.

Result when desktop expand: gambar

Result when sidebar collapsed: gambar

Result on mobile: gambar

Adding max-w-full class in SidebarInset fixes the problem for me

<SidebarInset className="max-w-full">
    ....
</SidebarInset>

thanks man 🙏🏻

In my case adding className="overflow-hidden" to SidebarInset solved the problem.

@kchro3 codesandbox link (fork): https://v0.dev/chat/K1ebiVKWPDV?b=JzbbCb0GaQc

Code snippet of the layout with header and sidebar:

return (
  <SidebarProvider>
    <AppSidebar />
    <SidebarInset className="overflow-hidden">
      <Header />
      <div className="flex-1 flex flex-col mx-auto p-6 w-full">{children}</div>
    </SidebarInset>
  </SidebarProvider>
);

image

using this my sticky header work on previous version, with this overflow hidden header not sticky anymore @damiankuchar

In my case works only using overflow-hidden inside of main content className.

may you can try this:

<SidebarInset className="max-w-[calc(100vw-var(--sidebar-width))] peer-data-[state=collapsed]:max-w-[calc(100vw-var(--sidebar-width-icon))]">

that solve my problem

In my case adding className="overflow-hidden" to SidebarInset solved the problem. @kchro3 codesandbox link (fork): https://v0.dev/chat/K1ebiVKWPDV?b=JzbbCb0GaQc Code snippet of the layout with header and sidebar:

return (
  <SidebarProvider>
    <AppSidebar />
    <SidebarInset className="overflow-hidden">
      <Header />
      <div className="flex-1 flex flex-col mx-auto p-6 w-full">{children}</div>
    </SidebarInset>
  </SidebarProvider>
);

image

using this my sticky header work on previous version, with this overflow hidden header not sticky anymore @damiankuchar

adding h-screen to SidebarInset fixed it for me