Skip to content

fix(theme): truncate long nav title with ellipsis - #5376

Open
xbsheng wants to merge 2 commits into
vuejs:mainfrom
xbsheng:fix/nav-title-overflow
Open

fix(theme): truncate long nav title with ellipsis#5376
xbsheng wants to merge 2 commits into
vuejs:mainfrom
xbsheng:fix/nav-title-overflow

Conversation

@xbsheng

@xbsheng xbsheng commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Problem

When the site title is longer than the sidebar width, the nav title text visually overflows its bordered title area and spills over the page content — e.g. 从零实现 DeepSeek Harness (~330px) vs the 17rem sidebar.

The title <span> is a flex item inside .VPNavBarTitle .title (display: flex). Flex items default to min-width: auto, so the span refuses to shrink below its text width and simply overflows the container (overflow: visible). The wrapper is already sized to var(--vp-sidebar-width) when a sidebar is present, so the only leak is the text itself.

Fix

Constrain the title text:

.title span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
  • min-width: 0 lets the flex item shrink below its content width
  • white-space: nowrap + overflow: hidden + text-overflow: ellipsis truncate the text instead of overflowing

No layout change when the title is short (no truncation kicks in), and non-sidebar pages are untouched (the wrapper there sizes to content).

Tests

Added __tests__/e2e/nav-title.test.ts with a deliberately long site title in the e2e fixture site:

  • title text does not overflow the sidebar (bounding-box comparison)
  • title text is truncated with ellipsis (scrollWidth > clientWidth)

Both fail without the fix, pass with it. Full suite green: test:types, test:unit (296), e2e dev (41) and e2e build (39) all pass.

Checklist

  • pnpm test:types passes
  • pnpm test:unit passes
  • pnpm test:e2e (dev + build) passes

The nav title could overflow the sidebar (and the whole nav bar) when the
site title was longer than the sidebar width: the title <span> is a flex
item that refuses to shrink below its content by default, so the text
visibly spilled over the bordered title area.

Constrain the title text with min-width: 0 + ellipsis so it truncates
instead of overflowing. The wrapper is already sized to the sidebar width
(VPNavBar .title), so this keeps the title aligned and contained.
@bluwy

bluwy commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

It looks like without min-width: 0 and white-space: nowrap, it also renders fine. Maybe we can remove it?

min-width: 0 is implied by overflow: hidden (flex automatic minimum
size computes to 0 for items with overflow != visible), and
white-space: nowrap is already inherited from .VPNavBar.
@xbsheng

xbsheng commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

You're right, both are redundant — verified and removed in 236a879:

  • min-width: 0: the span already has overflow: hidden, and per the flexbox spec an item with overflow != visible computes its automatic minimum size as 0, so the explicit declaration is a no-op.
  • white-space: nowrap: .VPNavBar already sets white-space: nowrap and the span inherits it.

The remaining rule is just overflow: hidden; text-overflow: ellipsis. The e2e tests (both dev and build mode) still pass, and the rendered title stays on a single line within the nav.

@bluwy bluwy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This seems good to me, but I don't know what's the convention for style-related tests. Personally I think it's fine without, but I'll leave @brc-dd to decide here.

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.

2 participants