ui: [bug]: vertical separator not rendering
Describe the bug
When using the separator with a “vertical” orientation it does not render properly. Looking at the browser dev tools it appears to have a size of 1x0 pixels.
Changing the default style here to use min-h-full instead of just h-full seems to fix this.
Seems to be the same as this issue encountered in the shadcn-svelte port
Affected component/components
Separator
How to reproduce
- Place a Separator in a flex parent with two other components and orientation “vertical”
<div className="flex flex-row flex-nowrap gap-4 h-fit">
<p>Foo</p>
<Separator orientation="vertical" />
<p>Bar</p>
</div>
- The separator will not appear
- Change style within components/ui/separator.tsx
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn(
'shrink-0 bg-border',
orientation === 'horizontal' ? 'h-[1px] w-full' : 'min-h-full w-[1px]',
className
)}
{...props}
/>
- Separator will now render
Codesandbox/StackBlitz link
https://stackblitz.com/edit/stackblitz-starters-t7h9sc?file=components%2Fui%2Fseparator.tsx
Logs
No response
System Info
M2 Mac,
Firefox
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: 10
- Comments: 15 (1 by maintainers)
I was using the block sidebar-08 and encountered the same issue rendering the new vertical separator with the provided code:
I was able to fix it by updating the class like this:
Hope this helps!
I had to use min-h-[] and border:
Issue (fix below)
I found the problem in my case. The parent needs a specific height for
h-fullto work.I confirmed this behavior with this snippet. You can add
height:100%;to the parent div to see the child fill up the parent components height.Fix
Either:
@shadcn this issue can be closed.
The
orientation="vertical"will not show if you add classitems-centerto its parent element.Solved it by removing
items-centerand modifyingh-fulltomin-h-fullotherwise it still won’t appear.doesn’t seem to work if the parent is display
flexand hasitems-centerto center fieldshad to go for grid
it has an easy fix, on the primitive root change:
setting min-h-full should fix this this issue when set to vertical
Yes explicitly setting a height does work but the default behavior of the component should be that it fills up the height of the parent which isn’t happening. Can always override that with the className prop even with this change
In my case, I had to define the height explicitly in the className prop. Then, it was displayed.
@garlic-brewlabs That’s because your container depends on the height of it’s inner content. Give the parent container an absolute height (like
h-12) and it will be fixed. I literally quoted:If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to auto
This problem still happening, more than 8 months now, any plans fixing it?
Opened a PR to help fix this!