Skip to content

fix(packages/ui): hide navbar divider when no items render to its right #92

@zrosenbauer

Description

@zrosenbauer

Summary

The navbar renders a vertical separator (NavMenuDivider) unconditionally inside the rp-nav__others container, even when no items (social links, dark/light toggle, language switcher, version switcher) are visible to its right.

Current behavior

In the upstream Rspress Nav component (@rspress/coreeject-theme/components/Nav/index.tsx:49-55), the divider is always rendered:

<div className="rp-nav__others">
  <NavMenuDivider />
  <NavLangs />
  <NavVersions />
  {hasAppearanceSwitch && <SwitchAppearance />}
  <SocialLinks />
</div>

When a zpress consumer disables social links, dark mode, langs, and versions, the .rp-nav-menu__divider 1px vertical line still appears with nothing beside it.

Expected behavior

The divider should not be visible when there are no sibling elements rendering content to its right.

Location

  • @rspress/core eject-theme/components/Nav/index.tsx ~line 50 — unconditional <NavMenuDivider />
  • @rspress/core eject-theme/components/Nav/NavMenu.css ~line 69 — .rp-nav-menu__divider styles
  • packages/ui/src/theme/components/nav/layout.tsx — zpress Layout wrapper

Proposed approach

Override via CSS in the zpress theme: use :has() to hide .rp-nav-menu__divider when it is the only visible child of .rp-nav__others, e.g.:

.rp-nav__others:not(:has(.rp-nav-menu__divider ~ *:not(:empty))) .rp-nav-menu__divider {
  display: none;
}

Or eject/override the Nav component to conditionally render the divider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions