emilkowalski / vaul

A drawer component for React.
https://vaul.emilkowal.ski
MIT License
6.02k stars 203 forks source link

Can't interact with Dialog opened on top of Drawer #245

Closed ghost closed 8 months ago

ghost commented 8 months ago

First, I want to say thanks for this library. It's saved us a great deal of time!

I noticed that there was a bug when a nested dialog is opened from within the drawer. Here's the codesandbox. Notice that when you open the drawer, then click "Open nested dialog", you are unable to interact with the nested dialog - pressing anywhere will close the bottom sheet that appears behind it first.

I thought it was because Vaul renders into the body. But I did the same for the nested modal, and even though it's higher in the stacking context hierarchy, the pointer events still hit the bottom sheet first. Some other things that might be relevant:

Any pointers for fixing this?

GrantClark1999 commented 8 months ago

I'm 90% sure I've done exactly this with the same setup without issues. I think your codesandbox is private but if you make it public I can take a look and see if I was doing anything differently with my setup.

ghost commented 8 months ago

Ah my bad! I've updated the permissions

emilkowalski commented 8 months ago

Make sure your modal has pointer-evevents: auto; set. This is an edge case and I generally don't recommend opening a modal on top of drawer, but if it's really necessary just add the pointer events to it.

ghost commented 8 months ago

That doesn't work. As you can see in the sandbox, the modal does have pointer-events: auto on it. Please re-open this issue.

emilkowalski commented 8 months ago

It does work, pointer-events just don't cascade when you have nested fixed elements. You need to add it to the element below. That being sad, upon interaction with the modal, the drawer will close. You should use modal={false} on Drawer.Root, that will enable you to interact with elements outside of the drawer withotu closing it. CleanShot 2024-02-02 at 09 44 28@2x

ghost commented 8 months ago

Thank you! I was able to find a fix. For future reference

The combination I found that works is:

Sandbox

There's some unfortunate flaws with this:

emilkowalski commented 8 months ago

Thanks a lot for the write up @tanishqk-shortwave.

I'll take a look at how the modal prop works and see whether we can improve it in the future.