AdaptiveTabs

AdaptiveTabs

HkAdaptiveTabs is one tab list with two renderings. On a wide viewport it is a tab strip: the canonical pill group with a sliding indicator, the arrow-key navigation and the per-key icon slots. Below 768px the same list collapses into a select-style trigger showing the active tab's icon, label and a caret, whose popup lists the options as rows — and on a phone that popup rises as a bottom sheet.

  • The value contract never changes shape: modelValue plus update:modelValue drive both forms, so a ?tab= deep link or a store-bound value keeps working across the breakpoint.
  • Reach for it for the button group a page chrome anchors to the header's or footer's center slot, where a squeezed ten-tab strip on a phone would spend space badly. A strip that must stay a strip, with its scroll behaviour and end actions, is HkTabs itself; a plain dropdown field is HkSelect.
  • It composes, it does not re-implement: the wide arm is HkTabs, the narrow arm is HkButton plus HkSelectPanel, and this component owns only the branch and the option rows.

Import

tsx
1
import { HkAdaptiveTabs } from "@celestia-island/hikari";

The component is exported as HkAdaptiveTabs and as the short alias HAdaptiveTabs. This page is Vue-only: there is no Rust mirror, and the crate's tab surface is SegmentedTabs, which mirrors the desktop HkTabs strip only — it has no breakpoint, no trigger and no sheet.

tabs is an array of TabItem ({ key, label, icon?, badge?, disabled? }, the same type HkTabs takes). Duplicate keys are dropped (the first wins) instead of rendering duplicate rows, and both ariaLabel and a badge without an accessible label raise a development-only console warning — the sheet rows and the strip share those rules.

The examples are written as block default exports (export default { setup() { return () => … } }) because they hold a ref; a stateless example is written as an arrow function. Either form satisfies the docs shell's module contract.

One list, two branches

The branch is useBreakpoint().isMobile, i.e. the viewport width below 768px — the same threshold the library's sheet family uses, so the narrow form arrives exactly when sheets would. Nothing about the value, the icons or the badges differs between the arms:

  • the wide arm renders <HkTabs> with variant, block, renderPanels and ariaLabel passed through, and every slot forwarded to it — including the per-key icon-<key> slots;
  • the narrow arm renders an HkButton (ghost, small) carrying the active tab's icon, its label, and a ChevronDown caret that rotates when the picker is open; the button is aria-haspopup="dialog" with aria-expanded following the open state;
  • the narrow arm's rows are buttons with data-checked on the current option and disabled on a disabled tab; pressing one closes the picker and emits update:modelValue unless the tab is disabled or already current.

variant is the wide arm's working mode — pill (the default, tablist / tab / aria-selected semantics) or segmented (radiogroup / radio / aria-checked). The narrow arm ignores it: a collapsed strip is one picker either way.

TSX

Icons and badges ride both forms

A tab's glyph comes from the icon-<key> slot when you provide one, and from TabItem.icon otherwise — the same precedence in both arms, so a tab never loses its icon when the list collapses. The named slot wins over the entry's vnode, which is what lets a host swap a glyph without rebuilding the array.

A TabItem.badge rides CornerBadge in both arms: beside the label on the wide strip, beside the row label in the picker. The component applies the strip's own rules to the rows so the two forms cannot drift — a count of zero still renders (showZero: a tab count is presence information, not notification noise), the offset default follows the placement (side marks sit flush, corner marks keep a 4px clearance), and a tab without a label gets no badge, because a badge anchors a label. Always pass badge.label (an accessible name such as "3 active"), or the mark is aria-hidden decoration and the count is announced nowhere.

TSX

Choosing a variant, and the props that are deliberately absent

block makes the wide strip fill its row (the form-row layout), placement decides where the narrow popup opens relative to the trigger — bottom-start by default (open downward), bottom-center, bottom-end, or the top-* mirror for a trigger pinned to the bottom of the viewport, such as a footer-center group. The popup auto-flips when the chosen side cannot host it.

renderPanels defaults to false here, not to HkTabs's true: this component renders triggers, and panel slots are not managed here — pass true only when the host supplies the panel slots for the wide arm. The HkTabs-only surface controls are not forwarded at all: disabled (the whole strip), scrollable, scrollbar, startAction / endAction and mergeKeys. A page-chrome group does not disable itself wholesale and does not carry strip decorations; if you need those, you want HkTabs directly.

TSX

Current range: week

Below the breakpoint

The narrow arm is the point of the component, and a still at a desktop viewport cannot show it: the branch is read from window.innerWidth, so the form only changes when the window is actually narrow. Resize below 768px and the strip collapses into the trigger; press it and the options list opens as a sheet.

Two details make the swap safe. Crossing the breakpoint in either direction resets the open flag, because the branch swap unmounts the panel in the same flush and the panel's own close-on-mobile watcher cannot run through its own unmount — without the reset, returning to a narrow viewport would re-open the sheet unbidden, and that re-open would also leave a spurious back-guard history entry. And the trigger's label falls back to the raw modelValue when no tab matches that value, so a value from a stale deep link still shows something rather than an empty button.

API

Vue

Props

NameTypeDefaultRequired
modelValueString—✓
tabsArray as PropType<TabItem[]>—✓
variant<code>String as PropType<"pill" | "segmented"></code>"pill"—
blockBooleanfalse—
renderPanelsBooleanfalse—
ariaLabelStringundefined—
placementString as PropType<SelectPanelPlacement>"bottom-start"—

Emits

EventPayload
update:modelValuestring

Accessibility

  • ariaLabel names all three narrow-arm surfaces at once — the trigger button, the sheet's header title, and (through the wide arm's HkTabs) the strip itself. Leaving it out trips a development warning, and the trigger and sheet would be unnamed.
  • The wide arm keeps HkTabs's semantics: role="tablist" with role="tab" and aria-selected in pill mode, role="radiogroup" with role="radio" and aria-checked in segmented mode, arrow/Home/End navigation with a roving tabindex, and disabled tabs skipped.
  • The narrow trigger is a button with aria-haspopup="dialog" and a live aria-expanded, so the open state is announced even though the caret's rotation is only visual; the caret itself is aria-hidden.
  • The narrow rows are buttons, not role="option" items: the current one carries data-checked (a class hook), not aria-checked. The picker is a dialog of buttons rather than a listbox, so the current option is announced through its position and label, not through a selected state — keep the labels distinct enough to tell apart.
  • A badge without a label is aria-hidden, and a development warning fires: the count would exist visually and nowhere in the accessibility tree. Pass badge.label with the count baked in ("12 unread").
  • Duplicate keys are dropped silently in production (a development warning names them); dropping is safer than rendering two rows that share an identity, but a key collision is always a host bug.

Related components

  • CornerBadge — the count mark a TabItem.badge rides in both forms.
  • NavSidebar — the ready-made navigation band, when the switch selects a page rather than a tab.
  • NavItem — the single navigation row, when the switch is a sidebar destination.
  • HkTabs — the strip this component wraps on wide viewports, with the scroll and decoration options it deliberately does not forward.
  • HkSelect — the plain dropdown field, when there is no tab strip to collapse at all.