Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown Menu doesn't allow scrolling #149

Closed
binajmen opened this issue Apr 2, 2023 · 15 comments · May be fixed by #6679
Closed

Dropdown Menu doesn't allow scrolling #149

binajmen opened this issue Apr 2, 2023 · 15 comments · May be fixed by #6679
Labels

Comments

@binajmen
Copy link

binajmen commented Apr 2, 2023

Is there a particular reason why Dropdown Menu does not allow scrolling, while Menubar does?

@krishraiturkar
Copy link

Can I help you

@adarshaacharya
Copy link

did you got any solution on this :( this is soo problematic

@joaom00
Copy link

joaom00 commented Oct 12, 2023

This is because of accessibility. If you want to keep the content outside of the dropdown interactive you can use modal={false} in DropdownMenu.Root

@skillnett
Copy link

Try wrapping https://ui.shadcn.com/docs/components/scroll-area
It helped me

@calebjoshuapaul
Copy link

Try wrapping https://ui.shadcn.com/docs/components/scroll-area It helped me

I tried it, It's not helping

@calebjoshuapaul
Copy link

Does anyone have a better solution?

@seblawrence
Copy link

Does anyone have a better solution?

This works:
Screenshot 2023-10-31 at 22 19 50

@aashish-dhiman
Copy link

aashish-dhiman commented Dec 23, 2023

Just add <DropdownMenu modal={false}> and It'll work.

@shadcn
Copy link
Collaborator

shadcn commented Jul 9, 2024

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 shadcn closed this as completed Jul 9, 2024
u007 pushed a commit to u007/ui that referenced this issue Sep 1, 2024
@iTh1nk
Copy link

iTh1nk commented Sep 4, 2024

Found out just have height defined and overflow scroll class added worked for me, like this :
<DropdownMenuContent align="end" className="bg-white overflow-y-scroll h-96"

@DanielCruz12
Copy link

Does anyone have a better solution?

This works: Screenshot 2023-10-31 at 22 19 50

thanks

@Lexachoc
Copy link

Lexachoc commented Oct 15, 2024

The cause is the <DropdownMenuPrimitive.Portal> in my case, when I put the DropdownMenu in Dialog (DialogContent) and I can't scroll inside the DropdownMenuContent (only possible by dragging the ScrollArea's ScrollBar with the mouse).

So I add a prop called isInsideDialog:

const DropdownMenuContent = React.forwardRef(({ className, sideOffset = 4, isInsideDialog = false, ...props }, ref) => {
    const content = (
      <DropdownMenuPrimitive.Content
        ref={ref}
        sideOffset={sideOffset}
        className={cn(
          "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
          "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
          className
        )}
        {...props}
      />
    );

    return isInsideDialog ? content : <DropdownMenuPrimitive.Portal>{content}</DropdownMenuPrimitive.Portal>;
  }
);
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName

When you're like me putting the DropdownMenu in Dialog for example, you can add this prop:

<DropdownMenuContent
    loop
    align="end"
    className="w-80"
    isInsideDialog={true} // TODO this is my fix
>
    <DropdownMenuLabel>My Account</DropdownMenuLabel>
    <DropdownMenuSeparator/>
    <ScrollArea className="h-96">
        {/* Your DropdownMenuItem*/}
    </ScrollArea>
</DropdownMenuContent>  

Then it can scroll now.

I tried with the modal={false} also, but it doesn't work and I still cannot scroll when I put the DropdownMenu in DialogContent, that's why I had to remove the use of <DropdownMenuPrimitive.Portal>.

@Zonalds
Copy link

Zonalds commented Dec 16, 2024

const DropdownMenuContent = React.forwardRef(({ className, sideOffset = 4, isInsideDialog = false, ...props }, ref) => {
const content = (
<DropdownMenuPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
);

return isInsideDialog ? content : <DropdownMenuPrimitive.Portal>{content}</DropdownMenuPrimitive.Portal>;

}
);
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName

Works, thanks

@valentingavran
Copy link

Shadcn should add the following properties to DropdownMenuContent

  1. max-h-[var(--radix-dropdown-menu-content-available-height)]
  2. overflow-y-auto

It would like this:

const DropdownMenuContent = React.forwardRef<
	React.ElementRef<typeof DropdownMenuPrimitive.Content>,
	React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & { container?: HTMLElement | null }
>(({ className, sideOffset = 4, container, ...props }, ref) => (
	<DropdownMenuPrimitive.Portal container={container}>
		<DropdownMenuPrimitive.Content
			ref={ref}
			sideOffset={sideOffset}
			className={cn(
				'z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md',
				'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
				className,
			)}
			{...props}
		/>
	</DropdownMenuPrimitive.Portal>
));
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;

With these properties, scrolling would be possible and the drop-down menu would take up the entire height available

Can someone open a PR for this?

paralin added a commit to paralin/ui that referenced this issue Feb 17, 2025
Fixes shadcn-ui#149

Add scrolling capability to `DropdownMenuContent` component.

* Modify `apps/v4/registry/new-york-v4/ui/dropdown-menu.tsx` to include `max-h-[var(--radix-dropdown-menu-content-available-height)]` and `overflow-y-auto` properties in `DropdownMenuContent` className.
* Update `apps/www/registry/default/ui/dropdown-menu.tsx` to add `max-h-[var(--radix-dropdown-menu-content-available-height)]` and `overflow-y-auto` properties in `DropdownMenuContent` className.
* Change `apps/www/registry/new-york/ui/dropdown-menu.tsx` to include `max-h-[var(--radix-dropdown-menu-content-available-height)]` and `overflow-y-auto` properties in `DropdownMenuContent` className.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/shadcn-ui/ui/issues/149?shareId=XXXX-XXXX-XXXX-XXXX).
@valentingavran
Copy link

I have created a PR myself. Also for the other components that open in a modal. Would be great if you could all support them 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet