ui icon indicating copy to clipboard operation
ui copied to clipboard

ScrollArea not working inside a Popover

Open mattiaz9 opened this issue 2 years ago • 18 comments

This is a code example:

<Popover>
  <PopoverTrigger>Open</PopoverTrigger>
  <PopoverContent>
    <ScrollArea className="flex max-h-16 flex-col" type="always">
      <div className="h-[800px] bg-red-500" />
    </ScrollArea>
  </PopoverContent>
</Popover>

The scrollbar appears but the scroll isn't working inside the content, only when i'm hovering over the scrollbar itself.

mattiaz9 avatar Jun 05 '23 15:06 mattiaz9

I've found I have to set a height value for this to work. Try with just 'h-16' as a className.

Scrolling with the mouse wheel doesn't seem to work though.

brooksa-chemtest avatar Jun 12 '23 10:06 brooksa-chemtest

Personally I fixed it by setting modal={true} to the Popover. It's a weird behaviour I have to say..

mattiaz9 avatar Jun 12 '23 11:06 mattiaz9

I had the same problem but reversed, a popover inside a scrollarea would not stay open. Using the setting modal={true} as stated by @mattiaz9 was my solution.

j-fdion avatar Jun 14 '23 17:06 j-fdion

Had the same problem using Commad and CommandList inside Popover. I had set overflow-y-auto and a max height on the CommandList. The scroll bar was showing and I could drag it, but scroll wheel was not working. When I pass modal={true} to the Popover, it scrolls normally. Setting height in CommandList didn't solve the problem.

henriqueup avatar Jul 31 '23 22:07 henriqueup

@mattiaz9 Thank you for this. setting Popover to modal fixed it for me as well

undesicimo avatar Sep 29 '23 07:09 undesicimo

Personally I fixed it by setting modal={true} to the Popover. It's a weird behaviour I have to say..

Thank you so much, it works

mamlzy avatar Oct 19 '23 03:10 mamlzy

@mattiaz9 Thanks! It works.

mununki avatar Nov 28 '23 07:11 mununki

@mattiaz9 thanks!

<Popover modal> 
  ....
    <ScrollArea>
      <CommandGroup>
        ....
      </CommandGroup>
    </ScrollArea>
  ....
</Popover>

zwergdev avatar Dec 18 '23 22:12 zwergdev

Try using "h-" instead of "max-h-" for setting the height of a scroll area.

SergiuPlesco avatar Jan 25 '24 07:01 SergiuPlesco

if i have an empty list, "h-" wouldn't make sense.

I would love to be able to use "max-h-" unfortunately Its not working.

roylee0704 avatar Mar 04 '24 02:03 roylee0704

For max-h, it needs to be set on the radix viewport, like this: <ScrollArea className={'[&>[data-radix-scroll-area-viewport]]:max-h-[300px]'}>

ArmandFrvr avatar Mar 22 '24 19:03 ArmandFrvr

@ArmandFrvr thanks for the solution. For me it works like a charm :)

mardrof avatar Mar 26 '24 16:03 mardrof

I had the same problem but reversed, a popover inside a scrollarea would not stay open. Using the setting modal={true} as stated by @mattiaz9 was my solution.

it worked for me, thanks @mattiaz9

krishnagkmit avatar Jun 04 '24 05:06 krishnagkmit

Personally I fixed it by setting modal={true} to the Popover. It's a weird behaviour I have to say..

thanks. worked for me

rafizuaf avatar Jun 04 '24 09:06 rafizuaf

Personally I fixed it by setting modal={true} to the Popover. It's a weird behaviour I have to say..

Worked for me, thanks!

iyy0v avatar Jun 04 '24 10:06 iyy0v

Adding modal to Popover "works" for scrolling, but is a bad solution for my use-case.

I'm using Popover with a Scroll Area for search results that appear as you are typing. I can prevent focus from being pulled into the popover but if focus is given to the popover at all (by scroll, tapping, etc), I can no longer re-focus on my input, because the modal flag disables interaction everywhere else on the page.

panzacoder avatar Jun 05 '24 18:06 panzacoder

I can confirm the solution posted by @ArmandFrvr works when the ScrollArea is nested within a Drawer.

mikechabotcandy avatar Jun 06 '24 00:06 mikechabotcandy

Personally I fixed it by setting modal={true} to the Popover. It's a weird behaviour I have to say..

Thank you for your solution it worked for me like a charm :)

MehrdadArman avatar Jun 27 '24 07:06 MehrdadArman

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jul 20 '24 23:07 shadcn

Personally I fixed it by setting modal={true} to the Popover. It's a weird behaviour I have to say..

Thanks. It works for me.

mamunur13525 avatar Jul 25 '24 20:07 mamunur13525