ui: ScrollArea not working inside a Popover

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.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 27
  • Comments: 43

Commits related to this issue

Most upvoted comments

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

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

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.

No previous solutions worked for me.

What worked was adding these to PopoverPrimitive.Content

<PopoverPrimitive.Portal>
  <PopoverPrimitive.Content
    ...
    onWheel={(e) => e.stopPropagation()}
    onTouchMove={(e) => e.stopPropagation()}
    ...
  />
</PopoverPrimitive.Portal>```

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.

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

@mattiaz9 thanks!

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

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.

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.

Has anyone overcome this issue when the popover is part of a modal/dialog?

I had the property modal={true} already set so I am not sure what the fix would be.

Any help would be much appreciated!

<Popover modal open={popoverOpen} onOpenChange={setPopoverOpen}>
  ...
  <PopoverContent className="w-auto p-2" align="center">
    <ScrollArea className={"[&>[data-radix-scroll-area-viewport]]:max-h-[300px]" >
    ...
    </ScrollArea>
  </PopoverContent>
</Popover>

pass modal as false then it will work for you

Has anyone overcome this issue when the popover is part of a modal/dialog? I had the property modal={true} already set so I am not sure what the fix would be. Any help would be much appreciated!

<Popover modal open={popoverOpen} onOpenChange={setPopoverOpen}>
  ...
  <PopoverContent className="w-auto p-2" align="center">
    <ScrollArea className={"[&>[data-radix-scroll-area-viewport]]:max-h-[300px]" >
    ...
    </ScrollArea>
  </PopoverContent>
</Popover>

I have the same issue, in my case, I remove <PopoverPrimitive.Portal> in popover.ui and it work

This causes the popover content to be clipped inside of dialogs, although it does restore scrolling. So for longer lists this solution isn’t viable.

Has anyone overcome this issue when the popover is part of a modal/dialog?

I had the property modal={true} already set so I am not sure what the fix would be.

Any help would be much appreciated!

<Popover modal open={popoverOpen} onOpenChange={setPopoverOpen}>
  ...
  <PopoverContent className="w-auto p-2" align="center">
    <ScrollArea className={"[&>[data-radix-scroll-area-viewport]]:max-h-[300px]" >
    ...
    </ScrollArea>
  </PopoverContent>
</Popover>

I have the same issue, in my case, I remove <PopoverPrimitive.Portal> in popover.ui and it work

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 , did you find the answer? I faced the similar issue.

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.