Components/TabBar

TabBar

A bottom navigation bar for an app's top-level destinations.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Indicator and Size

indicator sets how the slider behind the active item is drawn; size switches between sm, md, and lg.

Loading demo...

Best Practices

  • Keep three to five primary destinations, within reach of a thumb.
  • Use stable primitive values that map cleanly to routes or view keys.
  • Turn off fixed and safeAreaBottom inside previews, modals, and custom shells, or the bar pins to the real viewport bottom.
  • Keep badge short: a number or compact status text.
  • Don't nest interactive controls in labels; each item is already a button.

API Reference

Props

PropTypeDefaultDescription
modelValuestring | number''Active value (v-model).
itemsTabBarItem[][]Items, rendered left to right.
indicator'none' | 'pill' | 'line' | 'block' | 'dot''pill'Sliding indicator: color only, a raised surface, a top rule, a tint, or a dot.
size'sm' | 'md' | 'lg''md'Size tier; height, icon, label, and inset ship as inline CSS variables.
fixedbooleantruePins the bar to the viewport bottom with position: fixed.
safeAreaBottombooleantrueRenders an env(safe-area-inset-bottom) spacer below the items.
disabledbooleanfalseDisables every item and blocks value updates.
zIndexnumber2000Stacking level, written to --tx-tab-bar-z-index.

Events

EventPayloadDescription
update:modelValueTabBarValueThe picked item's value (v-model).
changeTabBarValueFires with the same value after an enabled item is picked.

Types

TabBarItem, one entry of items:

FieldTypeDescription
valuestring | numberValue emitted on selection.
labelstringVisible label.
iconClassstringIcon class shown above the label.
badgestring | numberBadge on the icon; null, undefined, and empty strings are hidden.
disabledbooleanDisables only this item.

Overview

  • The root is a <nav> landmark, not a tab widget, so it has no role="tablist". Each item is a <button>, and the active one has aria-current="page".
  • The indicator is measured by useIndicatorBox, as in TxSidebarNav; a ResizeObserver re-measures after a resize or font swap.
  • Only a new selection travels. The first measurement, a resize, a font swap, and a change of size or indicator land in place, as does every change under reduced motion.
  • The indicator never scales and lengthens only along the bar on the way; at either end it stops at the edge, so an overflow: hidden frame never clips it.
  • Picking a disabled item, or any item while disabled, emits nothing; picking the active item still emits update:modelValue and change.
  • Each size value is a CSS variable you can override on its own, such as --tx-tab-bar-height; an unknown size falls back to md.

Technologies

  • The indicator runs on the glide material of useJellyIndicator, shared with TxTabs, TxFlatRadio, and TxSidebarNav, and writes styles every frame without re-rendering.
  • Source: packages/tuffex/packages/components/src/tab-bar/.
查看源码
packages/tuffex/packages/components/src/tab-bar/index.ts