ui icon indicating copy to clipboard operation
ui copied to clipboard

asChild props on AlertDialogAction do not work

Open luvlaceeeee opened this issue 1 year ago • 2 comments

asChild props on AlertDialogAction do not work

I have this code element

...
       <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction asChild>
            <Button variant={'destructive'}>Continue</Button>
          </AlertDialogAction>
        </AlertDialogFooter>
...

And I wanted to make the button in the dialog box destructive, and I found that the asChild property does not work correctly with styles.

image

In the ui i comment this code

const AlertDialogAction = React.forwardRef<
  React.ElementRef<typeof AlertDialogPrimitive.Action>,
  React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
  <AlertDialogPrimitive.Action
    ref={ref}
    className={cn(buttonVariants(), className)}
    {...props}
  />
));
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
));
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName; 

and add this

const AlertDialogAction = AlertDialogPrimitive.Action;

And everything works fine

image

luvlaceeeee avatar May 29 '23 19:05 luvlaceeeee

No official solution to this yet?

spcbfr avatar Aug 10 '23 10:08 spcbfr

One possible temporary solution is:

<AlertDialogAction asChild>
  <>
    <Button variant="destructive">Delete</Button>
  </>
</AlertDialogAction>

dngpng avatar Apr 24 '24 06:04 dngpng

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jul 01 '24 23:07 shadcn