ui: [bug]: Can't open DropdownMenu when using with AlertDialog together
Describe the bug
export default function Test() {
const [open, setOpen] = useState(false);
return (
<div className="p-20">
<DropdownMenu>
<DropdownMenuTrigger>Open</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>My Account</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem>Profile</DropdownMenuItem>
<DropdownMenuItem>Billing</DropdownMenuItem>
<DropdownMenuItem>Team</DropdownMenuItem>
<DropdownMenuItem>Subscription</DropdownMenuItem>
<Button onClick={() => setOpen(true)}>open dialog</Button> // open dialog
</DropdownMenuContent>
</DropdownMenu>
<AlertDialog open={open}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your
account and remove your data from our servers.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => setOpen(false)}> // close dialog
Cancel
</AlertDialogCancel>
<AlertDialogAction>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
Can’t open DropdownMenu again after closing AlertDialog
Affected component/components
DropdownMenu, AlertDialog
How to reproduce
Codesandbox/StackBlitz link
https://codesandbox.io/p/sandbox/shadcnui-issue-44hxn3
Logs
No response
System Info
---
Before submitting
- I’ve made research efforts and searched the documentation
- I’ve searched for existing issues
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17
This should work fine for you, at least it works for me. I have the same situation as you.
I’ve faced the same issue in a recent app, I recently added the alert-dialog component, it’s already using the
v1.1.2of@radix-ui/react-alert-dialogand the problem still occurs. I’ve noticed that when the dialog is closed it is adding astyle="pointer-events: none;"property to thml body tag and it’s blocking the pointer event on the entire page.I’m pretty sure that it’s being added after close the dialog because I’ve monitored on devtools elements tab, and if you remove that style prop manually (from devtools elements tab) the page backs to normal.
same scenario, solved with
<AlertDialog open={open} onOpenChange={setOpen}>