emilkowalski / vaul

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

Drawer cannot be re-opened after swiping to dismiss #375

Closed shihfu closed 3 months ago

shihfu commented 3 months ago

After swiping to dismiss, the drawer cannot be re-opened when handling the state manually with the open prop.

See live example

https://codesandbox.io/p/devbox/drawer-without-scale-forked-kt4pt8?file=%2Fapp%2Fmy-drawer.tsx%3A12%2C39&workspaceId=5f8e56d5-8e4d-4048-8649-6e66cd8a5584

fabiosenracorrea commented 3 months ago

Same issue here!

TasseDeCafe commented 3 months ago

Same issue for me.

TasseDeCafe commented 3 months ago

I fixed this by passing this prop: onOpenChange={setIsDrawerOpen}

where:

const [isDrawerOpen, setIsDrawerOpen] = useState(false)

shihfu commented 3 months ago

I fixed this by passing this prop: onOpenChange={setIsDrawerOpen}

where:

const [isDrawerOpen, setIsDrawerOpen] = useState(false)

Can confirm this works. Thank you for sharing the solution @TasseDeCafe

sikandarchishty commented 3 months ago

I fixed this by passing this prop: onOpenChange={setIsDrawerOpen} where: const [isDrawerOpen, setIsDrawerOpen] = useState(false)

Can confirm this works. Thank you for sharing the solution @TasseDeCafe

When doing this, if you have an AlertDialog/Dialog from Radix or Shadcn inside Drawer, adding onOpenChange will close the Drawer but keep AlertDialog/Dialog open when clicked outside.

Alternate approach: add onRelease on Root

onRelease={()=>setIsDrawerOpen(false)} without using onOpenChange on Drawer

Bitnagar commented 3 months ago

I fixed this by passing this prop: onOpenChange={setIsDrawerOpen}

where:

const [isDrawerOpen, setIsDrawerOpen] = useState(false)

Thanks. This worked!