Closed Existential-Critic closed 8 months ago
@Existential-Critic
You can use onCloseAutoFocus
event on the DialogContent
component to update the state to the desired value
export function DialogDemo() {
return (
<Dialog>
<DialogTrigger>Open</DialogTrigger>
<DialogContent onCloseAutoFocus={() => console.log('closed')}>
<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>
);
}
https://github.com/shadcn-ui/ui/assets/150527559/94048b50-4a30-49f4-bcc4-c4f37dc17fef
This worked perfectly, thank you!
Hello,
I am trying to create a dynamic dialog window using Shadcn's UI. The dialog is a sign in window, which has 3 states: Sign In, Forgot Password, and Sign Up. When the dialog is opened, it should default to state 1, Sign In, and only change to state 2 or 3 (Forgot Password and Sign Up respectively) if the user clicks the buttons inside the dialog to change state.
However, when I close the dialog and go back to it, it stays on whichever state it was last on instead of reverting to state 1. How do I trigger the state resetting to 1 when the dialog window is closed?
const [dialogState, setDialogState] = useState(1);