Skip to content

docs(components): Manually Open and Close Dialog #7708

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

WillRy
Copy link

@WillRy WillRy commented Jun 29, 2025

Hello Everyone,

Sometimes you may want to control the dialog's open state manually, without a trigger component. You can do this by using the open prop and the onOpenChange callback.

This can be useful to demonstrate how to open the dialog without the need for a trigger element. It also demonstrates how to have more control over the dialog; in some scenarios it is necessary to open/close it through local states and even global states.

With these scenarios in mind, I have supplemented the documentation by demonstrating how to manually control the opening of the dialog.

A simple example of what I'm talking about

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"

import { useState } from "react";

export function ManuallyOpenDialog() {
  const [isOpen, setIsOpen] = useState(false)

  return (
    <>
      <Button onClick={() => setIsOpen(true)}>Open Dialog</Button>
      <Dialog open={isOpen} onOpenChange={setIsOpen}>
        <DialogContent>
          <DialogHeader>
            <DialogTitle>Are you absolutely sure?</DialogTitle>
            <DialogDescription>
              This action cannot be undone. This will permanently delete your
              account and remove your data from our servers.
            </DialogDescription>
          </DialogHeader>
        </DialogContent>
      </Dialog>
    </>
  )
}

Copy link

vercel bot commented Jun 29, 2025

Someone is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant