Underline Tabs with Sliding Indicator
A tab row on a hairline where one 2px indicator measures the active tab and slides to it. Use it to switch the top-level sections of a page, such as Overview, Deployments and Settings.
How it differs. One indicator element is measured against the active tab and moved, so no tab draws its own border. A row wider than its container scrolls, with paging buttons that stop at each end.
Install
pnpm dlx shadcn@latest add @hazine/tabs-underline-sliding-indicatorAdds 1 file, 1 shadcn primitive (tabs), and 2 packages (lucide-react, class-variance-authority).
First time? Add the registry to components.json
{
"registries": {
"@hazine": "https://api.hazine.dev/r/{name}.json"
}
}Needed once per project. Items resolve each other through the @hazine namespace.
The demo in the preview, 290 lines
"use client"
import * as React from "react"
import { ChevronRight } from "lucide-react"
import { Button } from "@/components/ui/button"
import {
TabsUnderlineSlidingIndicator,
TabsUnderlineSlidingIndicatorPanel,
type TabItem,
} from "@/components/hazine/tabs-underline-sliding-indicator"
const OUTCOMES = [
{ label: "Succeeded", count: 44 },
{ label: "Failed", count: 3 },
{ label: "Cancelled", count: 1 },
]
const DEPLOYMENT_COUNT = OUTCOMES.reduce((sum, outcome) => sum + outcome.count, 0)
const LATEST = [
{ label: "Retry failed webhooks with backoff", value: "Ready in 2m 14s" },
{ label: "Raise the upload limit to 50 MB", value: "Ready in 2m 2s" },
{ label: "Move the session store to Redis", value: "Failed after 48s" },
{ label: "Add a health check for the queue", value: "Ready in 1m 57s" },
]
const DOMAINS = [
{ label: "api.tidewater.dev", value: "Production" },
{ label: "staging-api.tidewater.dev", value: "Branch: staging" },
{ label: "harbor-api.tidewater.app", value: "Generated" },
]
const SETTINGS = [
{ label: "Region", value: "Frankfurt" },
{ label: "Runtime", value: "Node 22" },
{ label: "Build command", value: "pnpm build" },
{ label: "Deploys from", value: "main" },
]
const PROJECT_TABS: TabItem[] = [
{ value: "overview", label: "Overview" },
{ value: "deployments", label: "Deployments", count: DEPLOYMENT_COUNT },
{ value: "domains", label: "Domains", count: DOMAINS.length },
{ value: "settings", label: "Settings" },
]
function Lead({ lead, children }: { lead: string; children: React.ReactNode }) {
return (
<p className="text-sm text-muted-foreground">
<span className="font-medium text-foreground tabular-nums">{lead}</span>{" "}
<span className="tabular-nums">{children}</span>
</p>
)
}
function Ledger({ rows }: { rows: { label: string; value: string }[] }) {
return (
<dl className="mt-3 divide-y divide-border text-sm">
{rows.map((row) => (
<div
key={row.label}
className="flex items-baseline justify-between gap-4 py-2"
>
<dt className="min-w-0 truncate" title={row.label}>
{row.label}
</dt>
<dd className="shrink-0 tabular-nums text-muted-foreground">
{row.value}
</dd>
</div>
))}
</dl>
)
}
function ProjectPanels() {
return (
<>
<TabsUnderlineSlidingIndicatorPanel value="overview" className="@container">
<Lead lead={`${DEPLOYMENT_COUNT} deployments in November.`}>
{OUTCOMES[0].count} succeeded, {OUTCOMES[1].count} failed and{" "}
{OUTCOMES[2].count} was cancelled.
</Lead>
<dl className="mt-4 grid gap-px overflow-hidden rounded-xl border border-border bg-border bg-clip-padding @md:grid-cols-3">
{OUTCOMES.map((outcome) => (
<div key={outcome.label} className="bg-background p-4">
<dt className="text-sm text-muted-foreground">{outcome.label}</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight tabular-nums">
{outcome.count}
</dd>
</div>
))}
</dl>
</TabsUnderlineSlidingIndicatorPanel>
<TabsUnderlineSlidingIndicatorPanel value="deployments">
<Lead lead={`Latest ${LATEST.length} of ${DEPLOYMENT_COUNT}.`}>
Every push to main builds and goes live in Frankfurt.
</Lead>
<Ledger rows={LATEST} />
</TabsUnderlineSlidingIndicatorPanel>
<TabsUnderlineSlidingIndicatorPanel value="domains">
<Lead lead={`${DOMAINS.length} domains point here.`}>
Certificates renew on their own 30 days before they expire.
</Lead>
<Ledger rows={DOMAINS} />
</TabsUnderlineSlidingIndicatorPanel>
<TabsUnderlineSlidingIndicatorPanel value="settings">
<Lead lead="Build and runtime.">
Changes apply from the next deployment.
</Lead>
<Ledger rows={SETTINGS} />
</TabsUnderlineSlidingIndicatorPanel>
</>
)
}
export default function TabsUnderlineSlidingIndicatorDemo() {
return (
<div className="w-xl max-w-full">
<TabsUnderlineSlidingIndicator
aria-label="harbor-api project"
tabs={PROJECT_TABS}
>
<ProjectPanels />
</TabsUnderlineSlidingIndicator>
</div>
)
}
const MEMBER_COUNT = 58
const WORKSPACE_TABS: TabItem[] = [
{ value: "overview", label: "Overview" },
{ value: "deployments", label: "Deployments", count: 12480 },
{ value: "logs", label: "Runtime and build logs" },
{ value: "analytics", label: "Analytics" },
{ value: "domains", label: "Domains", count: 36 },
{ value: "environment", label: "Environment variables", count: 214 },
{ value: "storage", label: "Storage" },
{ value: "cron", label: "Scheduled jobs", count: 9 },
{ value: "firewall", label: "Firewall" },
{
value: "integrations",
label: "Integrations with source control, alerting and incident tools",
count: 1250000,
},
{ value: "members", label: "Members", count: MEMBER_COUNT },
{ value: "settings", label: "Settings" },
]
function OverflowScenario() {
return (
<div className="w-md max-w-full">
<TabsUnderlineSlidingIndicator
aria-label="Tidewater workspace"
tabs={WORKSPACE_TABS}
defaultValue="environment"
>
{WORKSPACE_TABS.map((tab) => (
<TabsUnderlineSlidingIndicatorPanel key={tab.value} value={tab.value}>
<Lead lead={`${tab.label}.`}>
One of {WORKSPACE_TABS.length} workspace sections, open to all{" "}
{MEMBER_COUNT} members.
</Lead>
</TabsUnderlineSlidingIndicatorPanel>
))}
</TabsUnderlineSlidingIndicator>
</div>
)
}
const LOADING_TABS: TabItem[] = PROJECT_TABS.map((tab) =>
tab.count === undefined ? tab : { ...tab, count: null }
)
function LoadingScenario() {
return (
<TabsUnderlineSlidingIndicator
aria-label="harbor-api project"
tabs={LOADING_TABS}
defaultValue="deployments"
className="w-xl max-w-full"
>
{LOADING_TABS.map((tab) => (
<TabsUnderlineSlidingIndicatorPanel
key={tab.value}
value={tab.value}
aria-busy="true"
>
<p className="sr-only" role="status">
Loading {tab.label.toLowerCase()}
</p>
<div aria-hidden="true" className="flex flex-col gap-3">
<div className="h-4 w-2/3 rounded-md bg-muted motion-safe:animate-pulse" />
<div className="h-9 rounded-md bg-muted motion-safe:animate-pulse" />
<div className="h-9 rounded-md bg-muted motion-safe:animate-pulse" />
<div className="h-9 rounded-md bg-muted motion-safe:animate-pulse" />
</div>
</TabsUnderlineSlidingIndicatorPanel>
))}
</TabsUnderlineSlidingIndicator>
)
}
const VIEWER_TABS: TabItem[] = [
...PROJECT_TABS.slice(0, 3),
{ value: "billing", label: "Billing", disabled: true },
PROJECT_TABS[3],
]
function DisabledScenario() {
return (
<div className="flex w-xl max-w-full flex-col gap-3">
<TabsUnderlineSlidingIndicator
aria-label="harbor-api project"
tabs={VIEWER_TABS}
defaultValue="domains"
>
<ProjectPanels />
</TabsUnderlineSlidingIndicator>
<p className="text-xs text-muted-foreground">
Billing is open to workspace owners only. Ask Ilse Brandt for access.
</p>
</div>
)
}
const REVIEW = { changes: 17, checks: 14, approvals: 2 }
const REVIEW_TABS: TabItem[] = [
{ value: "summary", label: "Summary" },
{ value: "changes", label: "Changes", count: REVIEW.changes },
{ value: "checks", label: "Checks", count: REVIEW.checks },
{ value: "approvals", label: "Approvals", count: REVIEW.approvals },
]
const REVIEW_NOTES: Record<string, string> = {
summary: "Release 2026.11.2 moves the session store to Redis.",
changes: `${REVIEW.changes} files changed across the api and worker packages.`,
checks: `${REVIEW.checks} of ${REVIEW.checks} checks passed on the release branch.`,
approvals: `${REVIEW.approvals} of ${REVIEW.approvals} required reviewers approved.`,
}
// The button outside the tabs never disables, so focus stays on it while it
// walks the sections and wraps from the last one to the first.
function ControlledScenario() {
const [value, setValue] = React.useState("changes")
const index = REVIEW_TABS.findIndex((tab) => tab.value === value)
const last = index === REVIEW_TABS.length - 1
const next = REVIEW_TABS[last ? 0 : index + 1]
return (
<div className="flex w-xl max-w-full flex-col gap-4">
<TabsUnderlineSlidingIndicator
aria-label="Release review"
tabs={REVIEW_TABS}
density="compact"
value={value}
onValueChange={setValue}
>
{REVIEW_TABS.map((tab) => (
<TabsUnderlineSlidingIndicatorPanel key={tab.value} value={tab.value}>
<p className="text-sm tabular-nums">{REVIEW_NOTES[tab.value]}</p>
</TabsUnderlineSlidingIndicatorPanel>
))}
</TabsUnderlineSlidingIndicator>
<div className="flex flex-wrap items-center gap-3">
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setValue(next.value)}
>
{last ? "Return to" : "Continue to"} {next.label.toLowerCase()}
<ChevronRight aria-hidden="true" className="rtl:rotate-180" />
</Button>
<p role="status" className="text-xs text-muted-foreground tabular-nums">
Section {index + 1} of {REVIEW_TABS.length}
</p>
</div>
</div>
)
}
export const scenarios = {
overflow: OverflowScenario,
loading: LoadingScenario,
disabled: DisabledScenario,
controlled: ControlledScenario,
}
Props5
- tabs
- TabItem[] = DEFAULT_TABS
- density
- "compact" | "default" | "comfortable" = "default"
- locale
- string = "en-US"
- Formats the counts.
- scrollBackLabel
- string = "Scroll tabs back"
- Names the button that scrolls an overflowing tab row toward its start.
- scrollForwardLabel
- string = "Scroll tabs forward"
- Names the button that scrolls an overflowing tab row toward its end.
Also accepts every prop of Omit<React.ComponentProps<typeof Tabs>, "orientation">.
Accessibility
- Keyboard
Keyboard support for Underline Tabs with Sliding Indicator Key Effect Tab Moves focus to the active tab, then into its panel Arrow Right, Arrow Left Moves to the next or previous tab, wrapping at the ends and skipping disabled tabs, and selects it. Mirrored in right-to-left layouts Home, End Moves to the first or last enabled tab and selects it - Screen reader
A tablist with automatic activation and a roving tab stop from the shadcn tabs primitive. Each panel is labelled by its tab. Counts are read in full, the indicator is decorative and the paging buttons are named but out of the tab order.
- Reduced motion
- The indicator jumps to the active tab without sliding, the row scrolls without easing and the count placeholders do not pulse.
- Checked
- Not checked yet. Automated results appear here once CI has run.
Dependencies3
- tabs
- lucide-react
- class-variance-authority
Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.
Tokens shipped0
None. The item is styled by the tokens your theme already has.