Temzasse / react-modal-sheet

Flexible bottom sheet component built with Framer Motion to provide buttery smooth UX while keeping accessibility in mind 🪐
https://temzasse.github.io/react-modal-sheet/
MIT License
791 stars 75 forks source link

Scroll conflicts when using inside a scrollable view #49

Closed ScreamZ closed 2 years ago

ScreamZ commented 2 years ago

Hello,

first I would like to thank you for providing this nice and easy library, we never tell it enough to OpenSource contributors so thank you 🙏🏻.


Now I would like to share two problems I've encountered using this library, to provide a bit of context I'm trying to build a marketplace and I would like at the same time I'm using the Infinite scroll to be able to pop this modal on top and having a scroll on it.

On that first problem, sometimes I'm taking control of the background instead of the first plan.

https://user-images.githubusercontent.com/6640835/135422875-6befc985-aa70-45d9-9118-d4532ea98d44.mp4

On that second one, you can see on IOS15 with the latest safari on an iPhone 12 pro-Max that I've some issue with the address bar, the utile fact is that I don't encounter this issue with https://temzasse.github.io/react-modal-sheet/#/scrollable for some reason, I've tried to compare my code and yours a bit seems not so different.

https://user-images.githubusercontent.com/6640835/135423531-5efc93b8-8e1b-4a07-aff1-321a70c85062.mp4

I guess something might conflict somewhere, maybe you could help me or give me some insight ? :)

Thanks

Temzasse commented 2 years ago

Hi @ScreamZ 👋🏻

The first scrolling issue can probably be solved with a body scroll locking library like this one. Framer Motion should handle body scroll locking automatically for draggable elements but it doesn't work all the time for some reason. So, I guess you can lock the body scroll every time you open the sheet and unlock it when the sheet closes.

I'm not sure if I should include a separate body scroll locking mechanism to this lib since it might not always be desirable to lock the scrolling when the sheet is open (eg. if you open the sheet on desktop etc). I would like to leave these kind of things to the end users. One place where automatic body scroll locking might make sense is the backdrop component since it most likely will alway cover the whole screen and thus you don't want to scroll anything behind it.

ScreamZ commented 2 years ago

I'm not sure if I should include a separate body scroll locking mechanism to this lib since it might not always be desirable to lock the scrolling when the sheet is open (eg. if you open the sheet on desktop etc). I would like to leave these kind of things to the end users. One place where automatic body scroll locking might make sense is the backdrop component since it most likely will alway cover the whole screen and thus you don't want to scroll anything behind it.

I guess too it doesn't belong to this library, but having a side note somewhere in the documentation giving this example could be nice. I'll use : https://mantine.dev/hooks/use-scroll-lock/ or this one from use-hook https://github.com/streamich/react-use/blob/master/docs/useLockBodyScroll.md