fix(Modal): use percentage sizing to prevent scrollbar flash#744
fix(Modal): use percentage sizing to prevent scrollbar flash#744huyenltnguyen merged 2 commits intofreeCodeCamp:mainfrom
Conversation
huyenltnguyen
left a comment
There was a problem hiding this comment.
Please provide more context on the issue and the fix, specifically the root cause and how the changes address it.
There was a problem hiding this comment.
For posterity, the root cause is:
The container has:
position: fixed;
inset: 0;
overflow: scroll;The Dialog (child of container) has:
width: 100vw;
height: 100vh;The conflict:
- Container with
overflow: scrollreserves space for scrollbars Dialogis sized at 100vw × 100vh = full viewport, meaningDialogis larger than the container's available content area- This creates overflow in both directions
During the close transition, there's a rendering frame where:
- The modal is transitioning out
- The container still has
overflow: scrollenforced, whileoverflow: hiddenset to thebodyis lifted (set by Headless UI, to enable body scroll lock) - The Dialog at
100vw × 100vhoverflows the container's content box - The scrollbars become visible on the container element
- When the modal completely fades out, these scrollbars disappear with it
This does not seem happen on modal open. It's probably because the transition happens quickly and body scroll lock is applied immediately, so there's no visual frame where the overflow scrollbars are noticeable.
The fix is to change Dialog's width and height to full, so it now sizes to 100% of container, not 100% of viewport.
src/modal/modal.tsx
Outdated
| {/* Full-screen container of the panel */} | ||
| <div | ||
| className={`fixed inset-0 flex items-start justify-center p-[10px] md:pt-[30px] md:pb-[30px] overflow-scroll`} | ||
| className={`fixed inset-0 flex items-start justify-center p-[10px] md:pt-[30px] md:pb-[30px] overflow-hidden`} |
There was a problem hiding this comment.
The overflow property should at least be auto. Otherwise, the content will get cut off if it's taller than the container.
Checklist:
mainbranch of the repo.Closes #743