Skip to content

AlertDialog unable to cancel when DialogTrigger is controlled #8139

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

Open
steveoh opened this issue Apr 24, 2025 · 2 comments
Open

AlertDialog unable to cancel when DialogTrigger is controlled #8139

steveoh opened this issue Apr 24, 2025 · 2 comments
Labels
waiting Waiting on Issue Author

Comments

@steveoh
Copy link
Contributor

steveoh commented Apr 24, 2025

Provide a general summary of the issue here

The close render prop of the AlertDialog does not have any affect on the Dialog when the DialogTrigger is controlled via isOpen.

🤔 Expected Behavior?

The AlertDialog should have the ability to close a controlled Dialog.

😯 Current Behavior

There is no way to update the controlled state of the Dialog from the AlertDialog.

💁 Possible Solution

Accept an onCancel prop that can be chained to the close

🔦 Context

I have a table with a destructive action that i would like to open an AlertDialog. In order to have one drigger, model, and dialog I figured I needed to control the state of the Dialog. Especially since the table has other Pressable items that would automatically open the Dialog which would not be desired.

🖥️ Steps to Reproduce

const [dialogOpen, setDialogOpen] = useState<boolean>(false);

<Button variant="destructive" onPress={() => setDialogOpen(true)}>
  Reject
</Button>

<DialogTrigger isOpen={dialogOpen}>
  <Modal>
    <AlertDialog
      title="Reject submission"
      variant="destructive"
      actionLabel="Reject"
      onCancel={() => {
        setDialogOpen(false);
      }}
      onAction={() => {
        setDialogOpen(false);
      }}
    >
      <div className="grid grid-cols-1 gap-4">
        ...
      </div>
    </AlertDialog>
  </Modal>
</DialogTrigger>

Version

react-aria-tailwind-starter.ab9fd5c68

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macos

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@LFDanLu
Copy link
Member

LFDanLu commented Apr 30, 2025

I've tested this locally in the tailwind starter via the following and it seems to work:

export function Test(args) {
  let [open, setOpen] = useState(false);
  return (
    <DialogTrigger isOpen={open} onOpenChange={setOpen}>
      <Button variant="secondary">Delete…</Button>
      <Modal>
        <AlertDialog {...args} />
      </Modal>
    </DialogTrigger>
  )
}

Test.story = {
  args: {
    title: 'Delete folder',
    children: 'Are you sure you want to delete "Documents"? All contents will be permanently destroyed.',
    variant: 'destructive',
    actionLabel: 'Delete'
  }
}

Am I misunderstanding the ask here?

@steveoh
Copy link
Contributor Author

steveoh commented May 1, 2025

I don't think you are missing anything. Is the difference that I am using onAction? I'll have to dig in a bit deeper.

@dannify dannify added the waiting Waiting on Issue Author label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting Waiting on Issue Author
Projects
None yet
Development

No branches or pull requests

3 participants