next.js 从Windows菜单阴影打开时,对话框未打开

bpzcxfmw  于 8个月前  发布在  Windows
关注(0)|答案(1)|浏览(66)

我正在使用nextJS与shadcn,并有以下问题.我试图打开一个对话框从菜单,但它不打开,它只是关闭菜单.我的猜测是,要么我需要使用ref和状态,或者我需要把alertdialog在不同的地方这里是代码:

return (
    <AlertDialog>
        <DropdownMenu>
            <DropdownMenuTrigger asChild>
                <Button variant="ghost" className="w-8 h-8 p-0">
                    <span className="sr-only">Open Menu</span>
                    <FiMoreHorizontal className="w-4 h-4" />
                </Button>
            </DropdownMenuTrigger>
            <DropdownMenuContent align="center">
                <DropdownMenuSeparator />
                <DropdownMenuItem className="justify-start cursor-pointer">
                    <Link href={`/dashboard/profile/trainee/${traineeId}`}>
                        Profile
                    </Link>
                </DropdownMenuItem>
                <DropdownMenuItem className="justify-start cursor-pointer">
                    <Link href={`/dashboard/profile/trainee/${traineeId}/escort/add-escort`}>
                        Add Escort
                    </Link>
                </DropdownMenuItem>
                <DropdownMenuItem className="justify-start cursor-pointer">
                    <AlertDialogTrigger>
                        Delete Trainee
                    </AlertDialogTrigger>
                </DropdownMenuItem>
            </DropdownMenuContent>
        </DropdownMenu>
        <AlertDialogContent>
            <AlertDialogHeader>
                <AlertDialogTitle>Are you sure you wish to delete the trainee?</AlertDialogTitle>
                <AlertDialogDescription>
                    This will delete the trainee and all of his data.
                </AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
                <AlertDialogCancel>Cancel</AlertDialogCancel>
                <AlertDialogAction onClick={() => deleteTrainee(traineeId)}>Continue</AlertDialogAction>
            </AlertDialogFooter>
        </AlertDialogContent>
    </AlertDialog>
)

字符串

6mw9ycah

6mw9ycah1#

你需要把对话框外的屏幕菜单:检查预置行动在右上角的这个页面的例子:https://ui.shadcn.com/examples/playground
验证码:

import * as React from "react"
  import { Dialog } from "@radix-ui/react-dialog"
  import { MoreHorizontalIcon } from "lucide-react"

  import {
    AlertDialog,
    AlertDialogCancel,
    AlertDialogContent,
    AlertDialogDescription,
    AlertDialogFooter,
    AlertDialogHeader,
    AlertDialogTitle,
  } from "@/components/ui/alert-dialog"
  import { Button } from "@/components/ui/button"
  Button
  import {
    DialogContent,
    DialogDescription,
    DialogFooter,
    DialogHeader,
    DialogTitle,
  } from "@/components/ui/dialog"
  import {
    DropdownMenu,
    DropdownMenuContent,
    DropdownMenuItem,
    DropdownMenuSeparator,
    DropdownMenuTrigger,
  } from "@/components/ui/dropdown-menu"

  export function ActionsCell(row) {
  console.log(row)
    const [open, setIsOpen] = React.useState(false)
    const [showDeleteDialog, setShowDeleteDialog] = React.useState(false)

    return (
      <>
        <DropdownMenu>
          <DropdownMenuTrigger asChild>
            <Button variant="secondary">
              <span className="sr-only">Actions</span>
              <MoreHorizontalIcon className="h-4 w-4" />
            </Button>
          </DropdownMenuTrigger>
          <DropdownMenuContent align="end">
            <DropdownMenuItem onSelect={() => setIsOpen(true)}>
              Content filter preferences
            </DropdownMenuItem>
            <DropdownMenuSeparator />
            <DropdownMenuItem
              onSelect={() => setShowDeleteDialog(true)}
              className="text-red-600"
            >
              Delete preset
            </DropdownMenuItem>
          </DropdownMenuContent>
        </DropdownMenu>
        <Dialog open={open} onOpenChange={setIsOpen}>
          <DialogContent>
            <DialogHeader>
              <DialogTitle>Content filter preferences</DialogTitle>
              <DialogDescription>
                The content filter flags text that may violate our content policy.
                It&apos;s powered by our moderation endpoint which is free to use
                to moderate your OpenAI API traffic. Learn more.
              </DialogDescription>
            </DialogHeader>
            <div className="py-6">
              <h4 className="text-sm text-muted-foreground">
                Playground Warnings
              </h4>

            </div>
            <DialogFooter>
              <Button variant="secondary" onClick={() => setIsOpen(false)}>
                Close
              </Button>
            </DialogFooter>
          </DialogContent>
        </Dialog>
        <AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
          <AlertDialogContent>
            <AlertDialogHeader>
              <AlertDialogTitle>Are you sure absolutely sure?</AlertDialogTitle>
              <AlertDialogDescription>
                This action cannot be undone. This preset will no longer be
                accessible by you or others you&apos;ve shared it with.
              </AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
              <AlertDialogCancel>Cancel</AlertDialogCancel>
              <Button
                variant="destructive"
                onClick={() => {
                  setShowDeleteDialog(false)
                  // toast({
                  //   description: "This preset has been deleted.",
                  // })
                }}
              >
                Delete
              </Button>
            </AlertDialogFooter>
          </AlertDialogContent>
        </AlertDialog>
      </>
    )
  }

字符串

相关问题