fix(ui): modal scrolling behavior on mobile #1620
Open
+18
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Moves the scrollable section one level down, placing it directly inside
<Drawer.Content />
as its child. This change ensures that when scrolling is active, no:after
pseudo-elements are unintentionally visible. Improves visual consistency and resolves minor aesthetic bugs related to scrollbars and overflow.Fixes: #1609
TL;DR
Although @aritradevelops were right in their #1612 PR about the use of Vaul's drawer that is shipped with some default CSS, the actual root cause was quite unexpected.
Issue Diagnosis
Who is the bad guy?
This was the first question to answer: how is it possible that the scrollable drawer from the official Vaul website does NOT have such an issue. Check this yourself: https://vaul.emilkowal.ski/default#scrollable. It also has that same
:after
pseudo-element withheight: 200%
property.And if you take a closer look, you may notice that the
<Drawer.Content />
isn’t the one getting scrolled when its content expands. Nope, it’s the first child<div>
block that’s hogging all the action!But why does it break the UI?
It's easy.
overflow: auto
enables scrolling for the drawer parent container (the<Drawer.Content />
component). The default CSS shipped with the package contains an:after
pseudo-element, which is a child of the parent container. Enabling scrolling for the parent container made all children — including the:after
— visible. Removingoverflow: auto
fixes the problem, but introduces another: the Create button gets cut off at the bottom.Ugh, what now?
Do you see that
max-h-[95h]
class on the parent element? It does a few things:Key point: if overflow is allowed. And guess what? It’s not! We removed it from the parent container, remember? Did we add one to any of its children? Nope!
So, what's the fix?
Adding
overflow
oroverflow-y
to the children of the<Drawer.Content />
allows them to handle scrolling when the inner content exceeds the specified height. Check the code for a clearer picture.Why this is anyway better than the fix suggested in #1612 PR?
I see two big red flags with overriding CSS globally:
Result
This is how the fixed modal looks on mobile:
Screen.Recording.2024-10-23.at.18.08.41.mov
And this is how it looks in full screen:
Screen.Recording.2024-10-23.at.18.11.07.mov