emilkowalski / vaul

An unstyled drawer component for React.
https://vaul.emilkowal.ski
MIT License
5.29k stars 170 forks source link

Is there a way to programatically close the drawer? #282

Closed cipriancaba closed 4 months ago

cipriancaba commented 4 months ago

This is needed for example after a server action runs, and needs to close the interaction that happened in the drawer

kevinmitch14 commented 4 months ago

Yes, you can use the open prop on the Root.

https://github.com/emilkowalski/vaul?tab=readme-ov-file#root

Can be controlled with the value and onOpenChange props. Can be opened by default via the open prop.

cipriancaba commented 4 months ago

That means that the only supported use case would be the fully controlled version, if I understand correctly?

kevinmitch14 commented 4 months ago

Yeah something like this probably works best - https://www.radix-ui.com/primitives/docs/components/dialog#close-after-asynchronous-form-submission

cipriancaba commented 4 months ago

Thanks for your help @kevinmitch14