Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cut the navbar items when it's too long (#2785) #2787

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

RiverTwilight
Copy link

This pull request addresses issue #2785, ensuring that when the navbar has many items or items with long names, the overflow is managed elegantly without pushing the logo out of view.

Previously, an overflow of menu items caused layout issues, leading to a cluttered and inaccessible navbar.

Before

image

After

Screenshot 2024-03-14 at 21 02 41

It's important to note that for most configurations, the visual appearance of the navbar remains unchanged:

Screenshot 2024-03-14 at 21 04 40

Copy link

changeset-bot bot commented Mar 14, 2024

⚠️ No Changeset found

Latest commit: a6e3d93

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Mar 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextra-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2024 5:56am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
nextra ⬜️ Ignored (Inspect) Visit Preview Mar 19, 2024 5:56am

Copy link

vercel bot commented Mar 14, 2024

@RiverTwilight is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@dimaMachina dimaMachina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now dropdown with type: 'menu' is hidden while opening

Screen.Recording.2024-03-15.at.01.14.25.mov

})}

<div className="nx-flex-auto nx-overflow-auto">
<div className="nx-flex nx-flex-row-reverse">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like now all links are in reversed order

@RiverTwilight
Copy link
Author

@dimaMachina The problems you mentioned are addressed. Currently if the menu is too long the search bar will be pushed out of the viewport, and the whole page will be scrollable on x-axis, which it's the best workaround, I think.

Screenshot 2024-03-15 at 16 35 18

@arno-fukuda
Copy link

arno-fukuda commented Mar 16, 2024

@dimaMachina The problems you mentioned are addressed. Currently if the menu is too long the search bar will be pushed out of the viewport, and the whole page will be scrollable on x-axis, which it's the best workaround, I think.

Screenshot 2024-03-15 at 16 35 18

I might be overcomplicating things but ideally I'd like to see the hamburger kick in as soon as the sum of the total navbar items width starts exceeding the current viewport width.

So if someone created 100 categories, it would immediately start off as hamburger menu, even on fullscreen.

@dimaMachina
Copy link
Collaborator

@dimaMachina The problems you mentioned are addressed. Currently if the menu is too long the search bar will be pushed out of the viewport, and the whole page will be scrollable on x-axis, which it's the best workaround, I think.
Screenshot 2024-03-15 at 16 35 18

I might be overcomplicating things but ideally I'd like to see the hamburger kick in as soon as the sum of the total navbar items width starts exceeding the current viewport width.

So if someone created 100 categories, it would immediately start off as hamburger menu, even on fullscreen.

this would be a perfect fix, not sure how to properly implement it, without overcomplicating things, any ideas are welcome

Also, I would accept the solution with overflow: scroll for nav links in navbar

@RiverTwilight
Copy link
Author

@dimaMachina The problems you mentioned are addressed. Currently if the menu is too long the search bar will be pushed out of the viewport, and the whole page will be scrollable on x-axis, which it's the best workaround, I think.

Screenshot 2024-03-15 at 16 35 18

I might be overcomplicating things but ideally I'd like to see the hamburger kick in as soon as the sum of the total navbar items width starts exceeding the current viewport width.

So if someone created 100 categories, it would immediately start off as hamburger menu, even on fullscreen.

this would be a perfect fix, not sure how to properly implement it, without overcomplicating things, any ideas are welcome

Also, I would accept the solution with overflow: scroll for nav links in navbar

Yes. I've thought about this idea but this might need JS to intercept, which makes the Navbar heavier, since we need dynamically measure the width of the available size and the horizontal stack width. Whatever I'll give another shot soon. There is no native CSS workaround to do this as far as I know.

The overflow solution seems not working as this cut dropdown menu (even only overflow-x is set to "scroll").

@RiverTwilight
Copy link
Author

RiverTwilight commented Mar 19, 2024

@dimaMachina Now it should be the expected behavior you want. If the items are too long it will be moved to sidebar, which's similar to mobile screen.

Screenshot 2024-03-19 at 13 55 50

Since the sidebar & hamburger share the same content, it's oevrcomplicated to let the hamburger contain the nav items and sidebar remains unchanged under overflow context.

Under the hood

I use JS to measure the nav items width and the available width. The navOverflow context will be updated to true if the nav items width reach 90%+ of the available width.

Feel free to drop any comment!

@arno-fukuda
Copy link

If the items are too long it will be moved to sidebar

I believe this won't work for pages that use raw or full layout theme which is often used for landing pages.

{
  "index": {
    "title": "Home",
    "theme": {
      "layout": "raw"
    }
  }
}

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.

None yet

3 participants