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
- fix: mouse wheel scroll over popover #607 #542 — committed to pa4080/shadcn-ui by pa4080 3 years ago
- fix: mouse wheel and touch scroll over popover #607 #542 — committed to pa4080/shadcn-ui by pa4080 3 years ago
- docs: fix typo PIN Input was misspelled as Pin Input (#542) — committed to u007/ui by at-wr 3 years ago
- feat: create and integrate PersonCard component - Add the following shadcn/ui components: - Avatar - Scroll-area - Add mock referee and player data - Style PersonCard within each Card component t... — committed to ash0545/tournament-software by ash0545 2 years ago
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
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!
Adding
modalto 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
modalflag 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!
pass modal as false then it will work for you
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.
I have the same issue, in my case, I remove <PopoverPrimitive.Portal> in popover.ui and it work
@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.