Skip to content

fix(Modal): use fixed positioning to avoid parent-dependent sizing#749

Merged
huyenltnguyen merged 1 commit intofreeCodeCamp:mainfrom
huyenltnguyen:fix/modal
Feb 9, 2026
Merged

fix(Modal): use fixed positioning to avoid parent-dependent sizing#749
huyenltnguyen merged 1 commit intofreeCodeCamp:mainfrom
huyenltnguyen:fix/modal

Conversation

@huyenltnguyen
Copy link
Member

Checklist:

#744 works but it causes Playwright failure:

62) [chromium] › video-modal.spec.ts:14:7 › Exit Video Modal E2E Test Suite › Verifies the Correct Rendering of the Video Modal 

    Error: Timed out 5000ms waiting for expect(locator).toBeVisible()

    Locator: getByRole('dialog', { name: 'Watch a Video' })
    Expected: visible
    Received: hidden
    Call log:
      - expect.toBeVisible with timeout 5000ms
      - waiting for getByRole('dialog', { name: 'Watch a Video' })
        9 × locator resolved to <div role="dialog" aria-modal="true" id="headlessui-dialog-6" data-headlessui-state="open" class="relative z-1050 w-full h-full" aria-labelledby="headlessui-dialog-title-8">…</div>
          - unexpected value "hidden"


      17 |     await expect(
      18 |       page.getByRole('dialog', { name: translations.buttons['watch-video'] })
    > 19 |     ).toBeVisible();
         |       ^
      20 |     await expect(
      21 |       page.getByTestId('video-modal-video-player-iframe')
      22 |     ).toBeVisible();
        at /home/runner/work/freeCodeCamp/freeCodeCamp/e2e/video-modal.spec.ts:19:7

https://github.com/freeCodeCamp/freeCodeCamp/actions/runs/21824605372/job/62967345618?pr=65786

This is because the internal Dialog uses relative w-full h-full, which can collapse when the portal parent has no explicit size.


The fix is to change to fixed inset-0:

  • position: fixed removes the Dialog from normal document flow and anchors it to the viewport (not its parent).
  • inset: 0 sets top/right/bottom/left: 0, so the Dialog exactly covers the viewport regardless of parent sizing or page scroll state.
  • Because it doesn't participate in the page's layout, it does not add to the scrollable area and doesn't introduce extra scrollbars or shifts caused by scrollbar width.
Screen recording (modal opens and closes correctly, without injecting scrollbars)
Screen.Recording.2026-02-10.at.01.15.30.mov

@huyenltnguyen huyenltnguyen marked this pull request as ready for review February 9, 2026 19:03
@huyenltnguyen huyenltnguyen requested a review from a team as a code owner February 9, 2026 19:04
@huyenltnguyen huyenltnguyen merged commit b88762e into freeCodeCamp:main Feb 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant