primitives
primitives copied to clipboard
DropDown menu does not closed when Drawer is inside the DropDownMenuItem
Here's the code that I used
<Dropdown.DropdownMenuItem asChild>
<MyForm />
</Dropdown.DropdownMenuItem>
My Form Code
<Drawer.Drawer open={isOpen} onOpenChange={setIsOpen}>
<Drawer.DrawerTrigger asChild>
<Button.Button variant="ghost">
<i className="fa-solid fa-users" />
<span className="tw-text-sm"> add item </span>
</Button.Button>
</Drawer.DrawerTrigger>
<Form.Form {...form}>
.....
</Form.Form>
</Drawer.Drawer>
Menu item showed on Drawer, to close it I need to close the Drawer and Click again to close the DropDownMenu
The same thing happens when you open the alert dialog from the dropdown menu. It seems that the wrong style, 'pointer-events: none;' is being added to the body
Actually I figured it out what actually happens
It is because two Triggers are overlapping with each other
DropDownMenu and Drawer both have triggers, so in order to work smoothly we have to remove trigger from child React Node
Here's an example
DropDownMenu
const [isDrawerOpen, setDrawerOpen] = useState < boolean > false;
const [isUploadOpen, setUploadOpen] = useState < boolean > false;
<Dropdown.DropdownMenu>
<Dropdown.DropdownMenuTrigger showTriggerIcon={false} variant="primary">
<span className="tw-text-sm"> open drop down </span>
</Dropdown.DropdownMenuTrigger>
<Dropdown.DropdownMenuContent>
<Dropdown.DropdownMenuItem asChild onClick={() => setDrawerOpen(true)}>
<div>
<i className="fa-solid fa-users tw-me-2 tw-text-gray-400 tw-text-lg" />
<span className="tw-text-sm"> Add DropdownMenuItem </span>
</div>
</Dropdown.DropdownMenuItem>
<Dropdown.DropdownMenuItem asChild onClick={() => setUploadOpen(true)}>
<div>
<i className="fa-solid fa-users-gear tw-me-2 tw-text-gray-400 tw-text-lg" />
<span className="tw-text-sm"> Add item 2 </span>
</div>
</Dropdown.DropdownMenuItem>
</Dropdown.DropdownMenuContent>
</Dropdown.DropdownMenu>
<DrawerComponent isDrawerOpen={isDrawerOpen} setDrawerOpen={setDrawerOpen} />
<DailgoComponent isUploadOpen={isUploadOpen} setUploadOpen={setUploadOpen} />
Drawer
<Drawer.Drawer open={isDrawerOpen} onOpenChange={setDrawerOpen}>
....
</Drawer.Drawer>
Dialog
<Dialog.Dialog open={isUploadOpen} onOpenChange={setUploadOpen}>
...
</Dialog.Dialog>