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
- Check out sidebar-01 in v0
- Add a very wide Table component into the main content so that it will exceed the available width
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
- feat: avoid scroll when sidebar is expanded as suggested in https://github.com/shadcn-ui/ui/issues/5545#issuecomment-2867696778 — committed to josuefuentesdev/helpdesk-ai by josuefuentesdev 2 years ago
In my case adding
className="overflow-hidden"toSidebarInsetsolved the problem.@kchro3 codesandbox link (fork): https://v0.dev/chat/K1ebiVKWPDV?b=JzbbCb0GaQc
Code snippet of the layout with header and sidebar:
I’ve used
<SidebarInset className="min-w-0" />and it resolved the layout issue for me.This approach doesn’t break any sticky elements inside, unlike setting overflow-hidden, which can interfere with sticky positioning.
Adding
max-w-fullclass in SidebarInset fixes the problem for meafter 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.tsxuseoverflow-auto:On the
header.tsxusefixedinstead ofstickyand use sidebar hooks andcn:Yea i need to calculate the width 100% - sidebar width for
expandedand 100% - sidebar width icon forcollapsed.Result when desktop expand:
Result when sidebar collapsed:
Result on mobile:
thanks man 🙏🏻
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-hiddeninside 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
adding
h-screentoSidebarInsetfixed it for me