Skip to content

Fix: Navigation overlay layout jitter - #77936

Open
DarkMatter-999 wants to merge 4 commits into
WordPress:trunkfrom
DarkMatter-999:fix/navigation-overlay-layout-jitter
Open

DarkMatter-999 wants to merge 4 commits into
WordPress:trunkfrom
DarkMatter-999:fix/navigation-overlay-layout-jitter

Conversation

@DarkMatter-999

Copy link
Copy Markdown
Contributor

What?

Closes #77571

When opening the Navigation block overlay, the page applies an overflow: hidden rule to the <html> root, which causes the browser's vertical scrollbar to disappear. This PR dynamically adds inline padding to the <body> equal to the width of the disappearing scrollbar, preventing the background page content from jumping to the side.

Why?

Currently, if a page has enough content to require a scrollbar, opening the navigation overlay causes an abrupt layout jitter ("text jump") because the viewport suddenly expands by the width of the missing scrollbar. This creates a jarring user experience.

How?

In the navigation block's interactive frontend logic (packages/block-library/src/navigation/view.js), we intercept the openMenu action before the has-modal-open class is applied. We calculate the scrollbar width. If a scrollbar is present, we temporarily apply an equivalent paddingLeft or paddingRight (respecting rtl attributes) to the document.body.

We cache any existing inline padding values before modifying them, and accurately restore them in the closeMenu action so we don't destructively overwrite theme or plugin-specific body paddings.

Testing Instructions

  1. Create/navigate to a page with enough text/content to ensure a vertical scrollbar is visible.
  2. Add a Navigation block and set the "Overlay Menu" setting to "Always".
  3. Add Navigation overlay and set its background to transparent and increase height to more than screen height (e.g., 100vw)
  4. Save and Click the hamburger icon to open the navigation overlay on the frontend.
  5. Notice that the background content stays perfectly in place and no longer shifts horizontally.
  6. Close the overlay and verify everything restores correctly.

Or follow the video linked in this issue comment

Screenshots or screencast

Before

navigation-overlay-jitter.mov

After

navigation-overlay-jitter-fix.mov

Use of AI Tools

Used Github Copilot(Gemini 3.1 Pro) to review the PR.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label May 5, 2026
@DarkMatter-999
DarkMatter-999 marked this pull request as ready for review May 5, 2026 08:00
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block library.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Mathijsvdbeek.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Mathijsvdbeek.

Co-authored-by: DarkMatter-999 <lakshyajeet@git.wordpress.org>
Co-authored-by: BlackStar1991 <blackstar1991@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text jump blog when overlay is opened

1 participant