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

[bug]: Popover cannot be worked properly inside Dialog with React 19 #6312

Open
2 tasks done
Sairaj-Aftab opened this issue Jan 9, 2025 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@Sairaj-Aftab
Copy link

Sairaj-Aftab commented Jan 9, 2025

Describe the bug

just example code here:

<Dialog> <DialogTrigger asChild> <Button>Open Dialog</Button> </DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>Are you absolutely sure?</DialogTitle> <Popover> <PopoverTrigger asChild className="flex-1 flex gap-2 flex-col justify-start" > <Button> <Input type="text" /> </Button> </PopoverTrigger> <PopoverContent className="flex flex-col gap-2 w-80"> <Input type="text" placeholder="more.." /> <Input type="text" placeholder="more.." /> <Input type="text" placeholder="more.." /> <Input type="text" placeholder="more.." /> </PopoverContent> </Popover> </DialogHeader> </DialogContent> </Dialog>

Screenshot_236

Affected component/components

Popover

How to reproduce

Click on

Codesandbox/StackBlitz link

No response

Logs

No response

System Info

Browser

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@Sairaj-Aftab Sairaj-Aftab added the bug Something isn't working label Jan 9, 2025
@Sairaj-Aftab Sairaj-Aftab changed the title [bug]: Popover cannot be worked properly inside Dialog [bug]: Popover cannot be worked properly inside Dialog with React 19 Jan 9, 2025
@shiqocred
Copy link

I also encountered the same issue, and I believe the problem lies in the conflict between the dialog Portal and popover Portal. I worked around it by creating a new file, duplicating the popover file, and removing <PopoverPrimitive.Portal>.

the file will be like this:

"use client"

import * as React from "react"
import * as PopoverPrimitive from "@radix-ui/react-popover"

import { cn } from "@/lib/utils"

const Popover = PopoverPrimitive.Root

const PopoverTrigger = PopoverPrimitive.Trigger

const PopoverAnchor = PopoverPrimitive.Anchor

const PopoverContent = React.forwardRef<
  React.ElementRef<typeof PopoverPrimitive.Content>,
  React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
  <PopoverPrimitive.Portal>
    <PopoverPrimitive.Content
      ref={ref}
      align={align}
      sideOffset={sideOffset}
      className={cn(
        "z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none 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}
    />
  </PopoverPrimitive.Portal>
))
PopoverContent.displayName = PopoverPrimitive.Content.displayName

export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants