fix(nav): put the prerelease badge beside the logo and never let the actions cover the tab pill

Both side columns keep their content width, so the pill gives way: it drops
its labels to icons when they no longer fit (measured, since plugins and
languages change the width) and scrolls only after that. The username is no
longer cut at 96px.
This commit is contained in:
Maurice
2026-10-14 10:45:09 +02:00
committed by Maurice
parent db531d2bef
commit b3ef13616f
4 changed files with 219 additions and 22 deletions
@@ -612,6 +612,27 @@ describe('Navbar layout (#1983)', () => {
expect(pill.style.overflowX).toBe('auto');
});
it('keeps both columns at their content width, so the actions never spill over the pill', () => {
withAddons(8);
const { container } = render(<Navbar />);
const nav = container.querySelector('nav') as HTMLElement;
const columns = Array.from(nav.children).filter(c => c.classList.contains('flex-1'));
// A min-w-0 column shrinks below its content and its justify-end children
// overflow leftwards across the pill (5.0.0-pre.1 feedback).
for (const c of columns) {
expect(c.classList.contains('min-w-0')).toBe(false);
expect(c.classList.contains('min-w-max')).toBe(true);
}
});
it('shows the prerelease badge in the brand column, beside the logo', () => {
seedStore(useAuthStore, { isPrerelease: true, appVersion: '5.0.0-pre.1' });
const { container } = render(<Navbar />);
const nav = container.querySelector('nav') as HTMLElement;
const brandColumn = nav.children[0] as HTMLElement;
expect(brandColumn.contains(screen.getByText('5.0.0-pre.1'))).toBe(true);
});
it('still renders every addon as a reachable link, however many there are', () => {
withAddons(8);
render(<Navbar />);
+35 -22
View File
@@ -12,6 +12,7 @@ import InAppNotificationBell from './InAppNotificationBell.tsx'
import HelpButton from '../Help/HelpButton'
import { resolvePluginIcon } from '../shared/PluginIcon'
import { visibleManagedNavItems } from '../../managed'
import { useCollapseOnOverflow } from '../../hooks/useCollapseOnOverflow'
const ADDON_ICONS: Record<string, LucideIcon> = { CalendarDays, Briefcase, Globe, Compass, Bookmark }
@@ -95,6 +96,16 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
return translated !== key ? translated : addon.name
}
const tabs = [{ id: '__trips', path: '/dashboard', label: t('nav.myTrips'), Icon: Briefcase },
...globalAddons.map(a => ({ id: a.id, path: `/${a.id}`, label: getAddonName(a), Icon: ADDON_ICONS[a.icon] || CalendarDays })),
...pagePlugins.map(p => ({ id: `plugin:${p.id}`, path: `/plugins/${p.id}`, label: p.name, Icon: resolvePluginIcon(p.icon) })),
// Empty in this repository — see client/src/managed.
...visibleManagedNavItems(user?.role === 'admin').map(m => ({ id: `managed:${m.id}`, path: m.path, label: m.label, Icon: m.Icon }))
]
// Labels go when they no longer fit beside the logo and the actions; the
// title and aria-label on each tab keep it named.
const { ref: pillRef, collapsed: pillCollapsed } = useCollapseOnOverflow<HTMLDivElement>(tabs.map(tab => tab.label).join('|'))
return (
<nav style={{
background: dark
@@ -113,8 +124,12 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
}} className="hidden md:flex items-center px-4 gap-4 fixed top-0 inset-x-0 z-[200]">
{/* Left side. flex-1 basis-0, matching the action cluster on the right, so
the tab pill between them sits in the middle of the bar rather than
being centred on top of both (#1983). */}
<div className="flex items-center gap-3 min-w-0 flex-1 basis-0">
being centred on top of both (#1983). Both columns keep at least their
content width (min-w-max): a column squeezed below it spilled over the
pill, so the pill is the one that gives way, first by dropping its
labels and then by scrolling. On a trip page there is no pill, and the
trip title truncates instead. */}
<div className={`flex items-center gap-3 flex-1 basis-0 ${tripTitle ? 'min-w-0' : 'min-w-max'}`}>
{showBack && (
<button type="button" onClick={onBack}
className="trek-back-btn p-1.5 rounded-lg transition-colors flex items-center gap-1.5 text-sm flex-shrink-0 text-content-muted"
@@ -130,6 +145,18 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
<img src={dark ? '/logo-light.svg' : '/logo-dark.svg'} alt="TREK" className="hidden sm:block" style={{ height: 28 }} />
</Link>
{/* Prerelease badge. Beside the logo it names the build, and it stays out
of the action cluster on the right, which has no room to spare once
plugins add tabs to the pill. */}
{isPrerelease && appVersion && (
<span
className="hidden sm:flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[11px] font-semibold flex-shrink-0 bg-[rgba(245,158,11,0.15)] text-[#d97706] border border-[rgba(245,158,11,0.3)]"
>
<span className="w-1.5 h-1.5 rounded-full flex-shrink-0 bg-[#f59e0b]" />
{appVersion}
</span>
)}
{tripTitle && (
<>
<span className="hidden sm:inline text-content-faint">/</span>
@@ -157,6 +184,7 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
than push the actions off the bar. */}
{(globalAddons.length > 0 || pagePlugins.length > 0) && !tripTitle && (
<div
ref={pillRef}
className="trek-nav-pill min-w-0"
style={{
display: 'flex', gap: 4, padding: 4, borderRadius: 14, flexShrink: 1,
@@ -166,17 +194,12 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
border: `1px solid ${dark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.05)'}`,
}}
>
{[{ id: '__trips', path: '/dashboard', label: t('nav.myTrips'), Icon: Briefcase },
...globalAddons.map(a => ({ id: a.id, path: `/${a.id}`, label: getAddonName(a), Icon: ADDON_ICONS[a.icon] || CalendarDays })),
...pagePlugins.map(p => ({ id: `plugin:${p.id}`, path: `/plugins/${p.id}`, label: p.name, Icon: resolvePluginIcon(p.icon) })),
// Empty in this repository — see client/src/managed.
...visibleManagedNavItems(user?.role === 'admin').map(m => ({ id: `managed:${m.id}`, path: m.path, label: m.label, Icon: m.Icon }))
].map(tab => {
{tabs.map(tab => {
const isActive = location.pathname === tab.path
return (
<Link key={tab.id} to={tab.path}
title={tab.label} aria-label={tab.label}
className="flex items-center gap-1.5 transition-colors"
className="flex items-center gap-1.5 whitespace-nowrap transition-colors"
style={{
padding: '5px 16px', borderRadius: 9, fontSize: 'calc(13.5px * var(--fs-scale-body, 1))', fontWeight: 500,
color: isActive ? 'var(--text-primary)' : 'var(--text-muted)',
@@ -186,7 +209,7 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
onMouseEnter={e => { if (!isActive) e.currentTarget.style.color = 'var(--text-primary)' }}
onMouseLeave={e => { if (!isActive) e.currentTarget.style.color = 'var(--text-muted)' }}>
<tab.Icon className="w-4 h-4" />
<span className="hidden lg:inline">{tab.label}</span>
<span className={pillCollapsed ? 'hidden' : 'hidden lg:inline'}>{tab.label}</span>
</Link>
)
})}
@@ -212,7 +235,7 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
is centred on the bar (#1983). Was a bare flex-1 spacer followed by
loose siblings, which centred nothing and left the pill to fend for
itself on top of them. */}
<div className="flex items-center gap-4 flex-1 basis-0 min-w-0 justify-end">
<div className="flex items-center gap-4 flex-1 basis-0 min-w-max justify-end">
{/* Share button */}
{onShare && (
@@ -225,16 +248,6 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
</button>
)}
{/* Prerelease badge */}
{isPrerelease && appVersion && (
<span
className="hidden sm:flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[11px] font-semibold flex-shrink-0 bg-[rgba(245,158,11,0.15)] text-[#d97706] border border-[rgba(245,158,11,0.3)]"
>
<span className="w-1.5 h-1.5 rounded-full flex-shrink-0 bg-[#f59e0b]" />
{appVersion}
</span>
)}
{/* Contextual help for the current screen — same footprint as the theme toggle beside it */}
{user && <HelpButton />}
@@ -268,7 +281,7 @@ export default function Navbar({ tripTitle, tripId, onBack, showBack, onShare }:
{user.username?.charAt(0).toUpperCase()}
</div>
)}
<span className="text-sm hidden sm:inline max-w-24 truncate text-content-secondary">
<span className="text-sm hidden sm:inline max-w-40 truncate text-content-secondary">
{user.username}
</span>
<ChevronDown className="w-4 h-4 text-content-faint" />