|Kit

NavigationProgress

Thin bar pinned to the top of the page while a navigation loads. It waits out fast loads, trickles toward 90% on slow ones, and runs to the end when loading stops.

NavigationProgress is the loading bar at the top edge of the viewport that sites like GitHub and YouTube show between pages, in the manner of nprogress and Mantine's NavigationProgress. It takes one boolean, loading, and invents the progress itself, because no router knows how far along a page load is.

import { NavigationProgress } from '@42-central/ui-react/navigation-progress';

<NavigationProgress loading={isNavigating} />

Demo

Try each speed. A fast load ends before the delay, so no bar appears. A slow load shows the trickle. In this demo the bar is pinned to the card instead of the viewport.

Code

<NavigationProgress loading={loading} color="neutral" />

Colors

color takes any palette color through the kit's data-color system, as Progress does. Use neutral for app chrome.

Code

<NavigationProgress loading={loading} color="blue" />

Code

<NavigationProgress loading={loading} color="green" size="sm" />

Gradient

variant="gradient" paints a gradient across the whole bar. The default goes from purple to pink. Pass gradient (from / via / to / dir) to set your own stops, using the same shape as Badge and Progress. The gradient spans the full width and the progress reveals it from the left, so the colors stay in place while the bar grows, and the final stop only shows at the end.

Code

<NavigationProgress loading={loading} variant="gradient" />

Code

<NavigationProgress
  loading={loading}
  variant="gradient"
  gradient={{ from: 'var(--color-cyan-400)', via: 'var(--color-blue-500)', to: 'var(--color-purple-500)' }}
/>

How it moves

  • Delay: nothing renders until loading has stayed true for delay ms (150 by default), so instant navigations don't flash a bar.
  • Trickle: the bar starts at a sliver. Every 200ms it closes a tenth of the remaining distance to 90%, so it moves quickly at first, then slows, and never finishes on its own.
  • Complete: when loading turns false, the bar runs to 100%, holds briefly, fades out, then snaps back to 0 with its transition off, so it never slides backwards.
  • Re-entry: if loading turns true again while the bar is still visible, it continues from where it is. If it had already reached 100%, it restarts from the sliver.
  • Reduced motion: when the user prefers reduced motion, there is no trickle and no reveal animation. The bar sits at full width while loading and fades when done.

With TanStack Router

Mount it once, in the root layout. Don't add it per route.

import { useRouterState } from '@tanstack/react-router';

export function RouteProgress() {
  const loading = useRouterState({ select: (s) => s.isLoading });
  return <NavigationProgress loading={loading} color="neutral" />;
}

Accessibility

The bar is aria-hidden. It repeats information the page change itself gives, and the router or page should announce that change, not the bar. That is why it is not a role="progressbar". For progress that has a real value, use Progress.

Styling

  • size sets the thickness. The default is xs (2px).
  • The bar is fixed at the top with z-index: var(--navigation-progress-z, 1000). Set that variable to move it under or over your overlays, or pass className="absolute" to pin it to a positioned parent.

Props

PropTypeDefault
loadingboolean(required)
delaynumber (ms)150
variant'filled' | 'gradient''filled'
colorColor (ignored for gradient)kit default solid
gradient{ from?, via?, to?, dir? }purple-300 → pink-400, to-r
size'xs' | 'sm' | 'md' | 'lg' | 'xl''xs'
className / classNames.root / classNames.barstring
testIdstring

Changelog

v0.21.0
  • New NavigationProgress: an nprogress-style bar at the top of the page that waits out fast loads, trickles toward 90% on slow ones and runs to the end when loading turns false

    #425
  • variant="gradient" with gradient={{ from, via, to, dir }}, the same shape as Progress and Badge

    #425

On this page