ui: I can't click anywhere after using alert dialog.
I wanted to implement alert-dialog into my dropdown menu but after I click to buttons I can’t click anymore I had to refresh site.
code:
"use client"
import { ColumnDef } from "@tanstack/react-table"
import { ArrowUpDown, Eye, EyeOff, MoreHorizontal } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { useRouter, useSearchParams } from "next/navigation"
import { useState } from "react"
export type Category = {
id: string
name: string
products: number
visibility: "public" | "private"
}
export const columns: ColumnDef<Category>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onCheckedChange={(value:any) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value:any) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
{
accessorKey: "name",
header: "Kategori",
cell: ({ row }) => <div>{row.getValue("name")}</div>,
},
{
accessorKey: "products",
header: "Ürün Sayısı",
cell: ({ row }) => <div>{row.getValue("products")}</div>,
},
{
accessorKey: "visibility",
header: "Görünürlük",
cell: ({ row }) => (
<div>
{row.getValue("visibility") === "public" ?
<><Eye className="mr-2 inline flex-1 text-sm text-muted-foreground" size={20}/>Herkese açık</> :
<><EyeOff className="mr-2 inline flex-1 text-sm text-muted-foreground" size={20}/>Gizli</>
}
</div>
),
},
{
id: "actions",
enableHiding: false,
cell: ({ row }) => {
const category = row.original
// eslint-disable-next-line react-hooks/rules-of-hooks
const router = useRouter()
const handleDelete = () => {
// Perform delete action here
// For example:
// deleteCategory(category.id)
// .then(() => router.push('/categories'))
}
// eslint-disable-next-line react-hooks/rules-of-hooks
const [isAlertDialogOpen, setAlertDialogOpen] = useState(false)
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Eylemler</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => setAlertDialogOpen(true)}>Kategoriyi Sil</DropdownMenuItem>
<DropdownMenuItem onClick={() => router.push(`/categories/edit/${category.id}`)}>Katogori Görünürlük</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => router.push(`/categories/edit/${category.id}`)}>Kategoriyi Düzenle</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<AlertDialog open={isAlertDialogOpen} onOpenChange={setAlertDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Emin misiniz?</AlertDialogTitle>
<AlertDialogDescription>
Bu eylem geri alınamaz. Bu eylem kategoriyi kalıcı olarak silecek.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => setAlertDialogOpen(false)}>İptal</AlertDialogCancel>
<AlertDialogAction>Devam et</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
)
},
},
]
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 36
Commits related to this issue
- feat: new calendar components (#468) — committed to u007/ui by sadeghbarati 3 years ago
- init: task solved approached this task as an opportunity to learn something new, so I decided to give ShadCN UI a try. Unfortunately, I ran into a few tricky bugs while implementing the features. I ... — committed to tzezar/nextjs-recruitment-task by tzezar 2 years ago
Setting
<DropdownMenu modal={false}>solved the problem bcs i had two modal in place.here’s what i found to solve:
@radix-ui/react-dropdown-menuto2.1.1modal={false}onDropdownMenuhope it helps.
In my case it appears that when i open my sheet within a DropdownMenuItem and closing the sheet afterwards the pointer event on the body remains none my fix was using
document.body.style.pointerEvents = ""if you are using any popover/alertdialog/modal inside dropdown-menu set the modal=false on DropdownMenu fixes this issue
<DropdownMenu modal={false}>Huge shout-out to whoever posted this query! I’ve been struggling with the exact same issue for days, and somehow I stumbled upon this thread. Finally, the solution worked perfectly for me !
This solution Worked for me …
<DropdownMenu modal={false}>Thank you ! Really…
If it helps anyone, ran into the same problem and inspired by the comments above I solved it using this:
Seems to be working well so for now.
To add to prev answer: the consistent way is to modify the
DialogPrimitive.Closecomponent. You have to do the setTimeout. It’s not great, happy to make a PR to issue a fix but I’m not exactly sure what the better solution is @shadcnThanks @Kiranism ! I was using a Dropdown with a Button trigger. DropdownItems was opening a modal. After closing that modal anything was not clickable anymore. Setting
modal={false}solved the issue.if you still have this problem, you can try using this code, i manage to open alert dialog inside the dropdown menu
This trick worked.
https://github.com/radix-ui/primitives/issues/1836#issuecomment-1674338372
you may also want to disable the modal of DropdownMenu by setting the value to false.
only second option worked on me, thanks @dalalRohit
Thanks @dalalRohit! Solved the modal and dropdown menu problem 😃 Another problem I was having was when using a Popover inside the modal inside the dropdownmenu, which I also managed to solve by putting
modal={true}in the Popover.Hi @wCatly and @UnknownBigBrain, did you try this?
“To activate the Dialog component from within a Context Menu or Dropdown Menu, you must encase the Context Menu or Dropdown Menu component in the Dialog component. For more information, refer to the linked issue here.”
From the documentation here: https://ui.shadcn.com/docs/components/dialog
THANKS!
Set modal on the dropdown menu to false
<DropdownMenu modal={false}>works for me.When using Shadcn components like
Popover,DropdownMenu, orSelectinside a modal/dialog, you need to setmodal={true}to prevent the portal from creating a new stacking context that can cause z-index and focus trapping issues.Example:
<Popover modal />Hope this helps
Here’s my solution.
w-fullto AlertDialogTrigger, and remove any propasChildThe code is here:
Here’s a workaround for Dialog and AlertDialog in the same level.
Thanks for the updates @braian-bernatto
In my case l’ve got that error because on my dialog component I’ve imported by error this line of code
import { DialogDescription } from '@radix-ui/react-dialog'instead ofimport { DialogDescription } from './ui/dialog'. Once I’ve changed it back it works as it should.