fix(theme): clip overflowed navbar menu - #5364
Open
bluwy wants to merge 2 commits into
Open
Conversation
bluwy
marked this pull request as draft
August 12, 2026 09:39
bluwy
marked this pull request as ready for review
August 12, 2026 09:48
bluwy
commented
Aug 12, 2026
| .button[aria-expanded="false"] + .menu { | ||
| opacity: 0; | ||
| visibility: hidden; | ||
| transform: translateY(0); |
Collaborator
Author
There was a problem hiding this comment.
This was removed because of a Safari bug that causes the menu to get wrongly clipped. It was also reported in #5050 before.
I noticed an easy fix here is to not use transform here (as it's also not doing anything). This could break for users that set translateY(-2px) or something to have a cool floating effect, but I think it's fine? Alternative I also found that setting will-change: transform fixes it, but this technically incurs some small perf overhead for everyone.
|
|
||
| .content { | ||
| flex-grow: 1; | ||
| min-width: 0; |
Collaborator
Author
There was a problem hiding this comment.
This min-width: 0 (on the flex item parent) allows shrinking the content beyond its content, same for the min-width: 0 in VPNavBarMenu. Both is needed to work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
In the navbar, make the navbar menu
flex-grow: 1(instead of the search bar) and clip it if there's no more space left, e.g. the screen isn't wide enough. Now, the navbar shouldn't ever exceed the screen width and cause the scrolling in the first placeI'll make some comments below explaining some of the changes.
Here's also a video of the new behaviour:
vitepress-navbar.mp4
Linked Issues
fix #2842
Additional Context
In the linked issue, the scrolling happened in the first place on smaller screens is because the navbar became
position: relative, while in larger screens it wasposition: fixed. I decided to fix this differently by making the navbar menu properly clipped in both cases instead.Tip
The author can publish a preview release by commenting
/publishafter creating the PR.