Skip to content

Add asynchronous trigger to Dialog, Collapsible... #4260

@chapman-cc

Description

@chapman-cc

Feature request

Summary

ad prop to <Dialog.Close> or <Dialog.Trigger> to await triggering closing a dialog upon success

Examples

function SaveDialog() {
  const mutation = useMutation({
    mutationFn: (data) => saveData(data),
  });

  return (
    <Dialog.Root>
      <Dialog.Trigger>Open Dialog</Dialog.Trigger>
      
      <Dialog.Portal>
        <Dialog.Backdrop />
        <Dialog.Viewport>
          <Dialog.Popup>
            <Dialog.Title>Confirm Changes</Dialog.Title>
            
            <Dialog.Description>
              Are you sure you want to proceed with this update?
            </Dialog.Description>

            <div className="controls">
              <Dialog.Close>
                Cancel
              </Dialog.Close>

              <Dialog.Close 
                resolve={() => mutation.mutateAsync()} 
                className="confirm-button"
              >
                Confirm
              </Dialog.Close>
            </div>
          </Dialog.Popup>
        </Dialog.Viewport>
      </Dialog.Portal>
    </Dialog.Root>
  );
}

Motivation

The dialog like components where there is a <Dialog.Trigger> or similar, can only handle syncronous events.
I would like a variation like <Dialog.AsyncTrigger resolve={promise}> to handle scenario where
user open a dialog, the footer has a button that does trigger an async action e.g. "Save" and then close the dialog upon success, and I don't have to add useState to control it to have a cleaner component composition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: dialogChanges related to the dialog component.status: waiting for maintainerThese issues haven't been looked at yet by a maintainer.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions