Tabs

Tabs

HkTabs is the library's one pill strip, and it works in two modes. variant="pill" (the default) is a tab strip: tablist / tab / aria-selected semantics, an optional panel below the strip, a sliding indicator and full arrow-key navigation in a single-choice strip. variant="segmented" is the same chrome used as a mutually exclusive option picker — radiogroup / radio / aria-checked, no panels, and the block extra that lets the strip fill its row.

  • Reach for pill when the options are peers of one content area and exactly one area is on screen; reach for segmented when the choice is a form value (a filter, a unit, a density) and nothing is revealed below it.
  • The Rust form, SegmentedTabs, mirrors the segmented variant only — it is a rendering subset, not a second implementation of the pill strip. The difference is the subject of the second section below.
  • The deprecated Rust Tabs shares this page's name and is a different component altogether: see Tabs (legacy). A strip that folds into one row on narrow screens is AdaptiveTabs.

Import

tsx
1
import { HkTabs, type TabItem, type TabsEndAction, type TabsTriggerAction } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // SegmentedTabs, SegmentedTabOption
use hikari_components::prelude::*; // SegmentedTabsProps, rsx!, VNode

The Rust form is a plain function, SegmentedTabs(SegmentedTabsProps { … }); Vue's tabs array is items there (a Vec<SegmentedTabOption> of key / label / attrs / disabled) and modelValue is active_key. Inside rsx! every prop may be omitted: active_key defaults to "" (which matches no option) and aria_label / class to the empty string.

Options, selection and the two modes

An option is { key, label } plus optional decoration: icon (a vnode before the label), badge (a count mark, described below), disabled, span (block strips only), actions (hover-revealed buttons attached to the option) and contextMenu (a right-click / long-press binding).

Keys must be unique and must not be $indicator or $merged. HkTabs keeps the first occurrence of a duplicate key and drops the rest, which keeps every index-derived feature — indicator, keyboard walk, merged runs — consistent with one option list.

Selection is controlled by modelValue: a press emits update:modelValue with the pressed key, and the component never changes the selection itself, so the host writes the value back. Re-pressing the already-active option emits nothing (unless that option carries actions — see "Attached actions"). variant="pill" renders the panels, variant="segmented" never does, whatever renderPanels says.

The two forms above are not two renderings of the same thing. The Vue side draws the panel area (renderPanels is on by default) and the Rust side draws only the strip, so the first card's Rust preview shows a segment strip where the TSX preview shows a strip plus its panel.

The Rust subset, and what it leaves to the host

SegmentedTabs emits exactly the DOM HkTabs renders in segmented mode before its measurement pass: root .hk-tabs[data-variant="segmented"] (plus the literal data-tauri-drag-region="false" the Vue render stamps), a .hk-tabs-list[role="radiogroup"] track, its sliding-indicator node (no data-ready, so the sheet keeps it transparent until a runtime measures it), and role="radio" triggers carrying aria-checked, data-active, data-key and the roving tabindex.

What it does not carry, on purpose:

  • no pill variant. There is no Rust form of tablist / tabpanel semantics, of renderPanels, of the panel slots, or of the mergeKeys / #merged cell. A Rust page that needs a tab strip with panels builds the reveal itself, or uses the Vue component.
  • no events and no state. The node is static: no on_change, no signals, no context. active_key is whatever the host passes in; a press renders no handler, so a Rust-only page cannot change its own selection.
  • no strip-level controls. disabled (the whole-strip flag), block (data-block / slot-unit distribution), startAction / endAction, scrollable, scrollbar and per-option icon / badge / span / actions / contextMenu have no counterpart. A disabled option is expressed per option (SegmentedTabOption::disabled), which the mirror does honour.
  • no keyboard. The Vue strip owns arrow keys, Home and End because role="radio" buttons have no native behaviour; the static node ships none of that behaviour. The tabindex contract is mirrored, though: the active option carries no tabindex (it joins the page's Tab sequence) and every other trigger is -1, so the group is one Tab stop whose arrow keys are the host's to implement.

Passthrough attributes are the escape hatch for that last point: SegmentedTabOption::attrs writes ("name", "value") pairs onto that trigger verbatim, after the mirror's own attributes, so a host's data-pane, aria-controls or hx-* hook can never be silently overwritten.

[D] One behavioural delta inside the tabindex contract: when active_key matches no navigable option (no match at all, or the matched one is disabled), Vue marks the first navigable trigger as the tab stop, and so does the mirror — the radiogroup never becomes keyboard-unreachable just because the selection is stale.

block is Vue-only: the TSX strip fills the 320px frame, while the Rust strip is content-sized inside the same frame. The stale-value second strip is identical in both forms — the fallback tab stop is the mirror's one piece of keyboard state, and it is written into the snapshot as an attribute.

Badges, attached actions and end actions

badge hangs an HkCornerBadge on the trigger's label: { count, max?, placement?, variant?, offset?, label? }. Zero stays visible — a tab count is presence information, not notification noise — and placement defaults to right (beside the label, vertically centred) rather than a corner overlay, because a tab is a button-group member. Give the mark a label ("3 changes"); without one the mark is aria-hidden decoration and the count is announced nowhere.

actions puts buttons beside a trigger: they are rendered as siblings of the trigger inside a .hk-tabs-cell wrapper (a button cannot nest a button), revealed on hover or focus-within, and never affect the selection. Each action needs a key and a label; a press calls its onSelect. On touch there is no hover, so pair them with the option's contextMenu binding — re-pressing the active option toggles its supplement open and shut, which is the tap path. Actions are ignored while their option is merged into the #merged cell.

startAction / endAction are protruding icon buttons at either inline end, outside the scroll viewport, revealed on hover or tap; a press emits action with "start" or "end". Their default glyph is a plus, their label falls back to "Add tab".

The badge on both labelled triggers and the end action are Vue-only state (HkCornerBadge, HkHoverRevealAction); the Rust mirror has neither, so the same strip renders as three bare labels there.

Panels, scrolling and the interaction surface

pill renders the active tab's panel in a .hk-tabs-panels area keyed on the active key: the outgoing panel cross-fades inside one grid cell while the container's height rides the incoming panel's natural size. The panel for an option is its key-named slot (slots[tab.key]), so v-slots={{ preview: () => … }} is the form that types. A segmented strip renders no panel at all, and the whole panel area drops out when the active key is merged.

The strip is wrapped in a horizontal scroller by default (scrollable): while the options fit they stay centred (or row-filling under block), and once the width runs short the strip carries the page bars' overflow behaviour — edge fades hint at hidden options, a swipe or wheel reaches them, and the active option is scrolled into view when the selection changes. scrollbar opts into the overlay scrollbar for host that want a drag affordance.

Keyboard navigation belongs to the track: Arrow Right / Arrow Down and Arrow Left / Arrow Up move the selection with wrap-around, Home and End jump to the first and last navigable option, disabled and merged-away options are skipped, and selection follows focus. Keys pressed inside a #merged cell's own interactive content are left alone. ariaLabel names the track (the tablist's or radiogroup's aria-label).

The example below is the interactive one: it keeps the selection in a ref and shows both panels, so switching tabs in the preview changes both the indicator and the panel area. The Rust form has no snapshot for it — a Rust example is declarative, and this strip is driven by the press.

TSX

Four unread messages.

API

Vue

Props

NameTypeDefaultRequired
modelValueString—✓
tabsArray as PropType<TabItem[]>—✓
variant<code>String as PropType<"pill" | "segmented"></code>"pill"—
blockBooleanfalse—
disabledBooleanfalse—
ariaLabelStringundefined—
renderPanelsBooleantrue—
scrollableBooleantrue—
scrollbarBooleanfalse—
startAction<code>Object as PropType<TabsEndAction | null></code>null—
endAction<code>Object as PropType<TabsEndAction | null></code>null—
mergeKeysArray as PropType<string[]>undefined—

Emits

EventPayload
update:modelValuestring
action<code>"start" | "end"</code>

Rust

Props — SegmentedTabs

PropTypeDefaultDescription
itemsVec<SegmentedTabOption>[]The options, in display order.
active_keyString""The key of the active option.
aria_labelString"".to_string()Accessible name for the radiogroup (mirrors HkTabs ariaLabel).
classString""—

Accessibility

  • The two modes announce different things on purpose. pill is a tablist whose triggers are tabs with aria-selected, and the panel below is a tabpanel; segmented is a radiogroup whose triggers are radios with aria-checked. Both tracks take their accessible name from ariaLabel — an unnamed radiogroup inside a named popover is exactly what the label exists to prevent, so pass one whenever the strip stands alone.
  • The track carries a roving tabindex: the active option is the group's single Tab stop and the others are -1, reachable with the arrow keys. When the selection matches no navigable option the first navigable one takes the stop instead, so the group is never keyboard-unreachable. A disabled option is aria-disabled and disabled (skipped by the Tab order and by arrow navigation), and a whole-strip disabled puts every trigger in that state.
  • The sliding indicator is decoration: the selection is already stated by aria-selected / aria-checked, so nothing depends on seeing the pill move. The data-ready fade only stops a pop-in on mount.
  • A badge without label renders aria-hidden, so the count is announced nowhere. Pass label ("4 unread") to keep the count in the accessible name; a trigger slot (trigger-<key>) replaces the icon and badge entirely, so it must carry its own accessible name.
  • Attached actions are real buttons with aria-label and a native title, but they are only revealed on hover or focus-within; on touch the reachable path is the option's contextMenu binding or a re-press of the active option.
  • SegmentedTabs ships the same roles, names and tabindex contract but no behaviour: focus moves with the page's Tab key only, and the arrow keys it advertises in role="radio" semantics are the host's to implement.

Related components

  • Tabs (legacy) — the deprecated Rust Tabs / TabPane: same name, a different component, no Vue counterpart.
  • AdaptiveTabs — a tab bar that folds overflowing options into one menu row instead of scrolling them.
  • PillToggleGroup — the same pill chrome for a multi-choice toggle rather than one selection.
  • MenuPanel — the menu list container, when the strip's options open menus rather than panels.