Skip to content

How do I trigger a Dialog from an outside component? #497

Closed Answered by vladmoroz
samuelneff asked this question in Q&A
Discussion options

You must be logged in to vote

You'll need to add the onOpenChange prop. Not sure I totally get how your app is supposed to work here, but if I'm reading it right, your current problem would be that the dialog doesn’t close because its open state depends on whether an icon is selected, but isn't cleared when the user attempts to close it.

<Dialog.Root
  open={!!selectedIcon}
  onOpenChange={open => {
    if (!open) {
      setSelectedIcon('');
    }
  }}
/>

Is this what you are looking for?

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by samuelneff
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #495 on May 14, 2024 07:29.