Scroll Area doesn't work with css max-height
Bug report
Scroll Area doesn't work with css max-height
Current Behavior
Scroll Area only works with fix css height
Expected behavior
Should also work with max-height
When used together with Dropdown Menu, I want to only show scroll-bar when items overflow the maximum height of the Scroll Area.
Reproducible example
The max-height should be set on Viewport
The
max-heightshould be set onViewport
Still not working. I also tried making a custom wrapper div and sets a max-height on it`. Still not working.
I've made a work around
<DropdownMenu.Portal>
<DropdownMenu.Content align='start'>
{items && items?.length > 9 ? (
<ScrollArea className='h-72 pr-2'>
{items?.map(i => <DropdownItem key={i.label} {...i} />)}
</ScrollArea>
) : (
items?.map(i => <DropdownItem key={i.label} {...i} />)
)}
</DropdownMenu.Content>
</DropdownMenu.Portal>
Here is working though https://codesandbox.io/p/sandbox/zen-mclaren-v3wj6t?file=%2Fstyles.css%3A9%2C22
Here is working though https://codesandbox.io/p/sandbox/zen-mclaren-v3wj6t?file=%2Fstyles.css%3A9%2C22
Wow, thanks I thought, you mean the viewport from the dropdown 😄 My bad haha
Thanks again @joaom00
Here is working though https://codesandbox.io/p/sandbox/zen-mclaren-v3wj6t?file=%2Fstyles.css%3A9%2C22
Hello you repository have no credits, can't oppen it :(
Here is working though https://codesandbox.io/p/sandbox/zen-mclaren-v3wj6t?file=%2Fstyles.css%3A9%2C22
Hello you repository have no credits, can't oppen it :(
@Asandolo You can sign in and fork it and run it on your account.
Here is working though https://codesandbox.io/p/sandbox/zen-mclaren-v3wj6t?file=%2Fstyles.css%3A9%2C22
Hello you repository have no credits, can't oppen it :(
@Asandolo You can sign in and fork it and run it on your account.
unfortunalty i have a 401 :
Failed to fork: (401) You don't have the needed authorization for this workspace (joaom00).
Everything wrong with OSS in one thread
For me this works worked fine for dynamic height:
<CommandList>
<CommandEmpty>No results</CommandEmpty>
<CommandGroup>
<ScrollArea className="flex max-h-40 flex-col overflow-y-auto">
{frameworks.map((framework) => (
<CommandItem
key={framework.value}
value={framework.value}
onSelect={(currentValue) => {
setValue(currentValue === value ? '' : currentValue);
setOpen(false);
}}
>
<Check
className={cn(
'mr-2 h-4 w-4',
value === framework.value ? 'opacity-100' : 'opacity-0',
)}
/>
{framework.label}
</CommandItem>
))}
</ScrollArea>
</CommandGroup>
</CommandList>
@KasperiP Solution works, but we don't need overflow-y-auto as its already flex.
Additionally for horizontal scroll one can use flex max-w-30 should work to obtain same behaviour
flex max-h-40 flex-col overflow-y-auto
This works just fine. Thank you very much
flex max-h-40 flex-col overflow-y-autoThis works just fine. Thank you very much
Tnx this works for me too.
flex max-h-40 flex-col overflow-y-autoThis works just fine. Thank you very much
This works very well. Can someone explain why and how does it work?
max-h-40 overflow-y-auto
This works but does not use the ScrollView properties like custom scrollbar etc.
It just as much as adding same class names to a div.
So ideally this does not solve the issue.
max-h-40 overflow-y-autoThis works but does not use the ScrollView properties like custom scrollbar etc. It just as much as adding same class names to adiv. So ideally this does not solve the issue.
Agree with @usmangurowa . I am seeing the same behavior in my project.
flex max-h-40 flex-col overflow-y-auto
Finally, this is what work for me without overflow-y-auto, which case double scrollbar
@issam-seghir thanks a lot, worked like a charm
flex max-h-40 flex-col overflow-y-auto is not the solution. You dont get the nice scroll bar thumb
I tried using selector to target the Viewport and it works for me.
<ScrollArea className="[&_[data-slot=scroll-area-viewport]]:max-h-40">
...
</ScrollArea>