primitives icon indicating copy to clipboard operation
primitives copied to clipboard

Scroll Area doesn't work with css max-height

Open stonix26 opened this issue 3 years ago • 19 comments

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

CodeSandbox

stonix26 avatar Jul 27 '23 20:07 stonix26

The max-height should be set on Viewport

joaom00 avatar Jul 27 '23 20:07 joaom00

The max-height should be set on Viewport

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>

stonix26 avatar Jul 27 '23 22:07 stonix26

Here is working though https://codesandbox.io/p/sandbox/zen-mclaren-v3wj6t?file=%2Fstyles.css%3A9%2C22

joaom00 avatar Jul 28 '23 00:07 joaom00

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

stonix26 avatar Jul 28 '23 00:07 stonix26

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 avatar Feb 14 '24 14:02 Asandolo

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.

jad-eljerdy avatar Feb 19 '24 01:02 jad-eljerdy

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

Asandolo avatar Feb 19 '24 14:02 Asandolo

Everything wrong with OSS in one thread

elliotsayes avatar Mar 21 '24 00:03 elliotsayes

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 avatar Jul 28 '24 10:07 KasperiP

@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

5war00p avatar Aug 09 '24 07:08 5war00p

flex max-h-40 flex-col overflow-y-auto

This works just fine. Thank you very much

RanitManik avatar Sep 25 '24 15:09 RanitManik

flex max-h-40 flex-col overflow-y-auto

This works just fine. Thank you very much

Tnx this works for me too.

mrghasemi1992 avatar Oct 03 '24 06:10 mrghasemi1992

flex max-h-40 flex-col overflow-y-auto

This works just fine. Thank you very much

This works very well. Can someone explain why and how does it work?

Agros-Hokhy avatar Nov 25 '24 09:11 Agros-Hokhy

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.

usmangurowa avatar Dec 22 '24 20:12 usmangurowa

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.

Agree with @usmangurowa . I am seeing the same behavior in my project.

maxchu92 avatar Jan 05 '25 16:01 maxchu92

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 avatar May 03 '25 06:05 issam-seghir

@issam-seghir thanks a lot, worked like a charm

pjeziorowski avatar Jul 02 '25 09:07 pjeziorowski

flex max-h-40 flex-col overflow-y-auto is not the solution. You dont get the nice scroll bar thumb

ss-joy-dviz avatar Jul 02 '26 12:07 ss-joy-dviz

I tried using selector to target the Viewport and it works for me.

<ScrollArea className="[&_[data-slot=scroll-area-viewport]]:max-h-40">
...
</ScrollArea>

viyic avatar Jul 06 '26 05:07 viyic