PillToggleGroup

PillToggleGroup

HkPillToggleGroup is the segmented pill track: a row of small toggle buttons sharing one chrome, where every pill can be on at the same time. It is the multi-select counterpart of a tab strip — a tab's sliding indicator says "one of these", while a pill's own tint says "this one is on, and so may be its neighbours". Reach for it when a handful of independent facets are switched together: a filter bar, a set of display columns, a view's overlays.

  • One choice out of a short list is a HkRadio group, or a segmented control; five or more options that must open a list belong in HkSelect.
  • An independent on/off that needs a caption belongs in HkCheckbox; one that is a plain switch in a form row is a HkSwitch.
  • A single value along a track is a HkSlider.

Import

tsx
1
import { HkPillToggleGroup, type HkPillToggleGroupOption, type HkPillTone } from "@celestia-island/hikari";

The group is deliberately thin: selected is the single source of truth and the component never mutates it — a press reports toggle(value), and your state writes the new set back. The optional leading pill reports all() and the host decides what that means: clear the filter, or pick everything.

Selection and the all-pill

options is the list, each entry a value, a label, and optionally an icon (a component or a prebuilt vnode) and a tone. selected is a Set of the picked values; a pill is on when its value is in it, and the allLabel pill is on exactly when nothing is picked — which is what a facet that means "no restriction" needs. Omit allLabel and the leading pill is not rendered at all.

TSX

Tones

tone decides the tint a pill wears while it is on. Omit it — or say primary — for the default primary wash; success, secondary, warning, error and muted re-tint the active pill only, so a filter bar can keep each facet's own colour identity while every pill shares the same chrome. An inactive pill stays muted whatever its tone says, which keeps the track readable when half of it is on.

TSX

The pannable strip

The track is one line that hugs its pills and pans when they overflow: the wheel moves it sideways (a vertical notch is translated onto the horizontal axis), a mouse drag pans it, a touch swipe scrolls it natively. When the strip overflows it raises a data-h-overflow marker for the host to style — the component itself ships no edge fade. A press only becomes a pan once the pointer strays 5px, so a plain click still toggles — and the click a pan leaves behind is swallowed exactly once, so dragging never switches a facet by accident. On phones the track relaxes back into a wrapping group, where the pan is not needed.

The track hugs its pills rather than filling the lane, so a two-option group inside a narrow table cell frames its own width instead of a bordered empty box. disabled makes every pill inert, the all-pill included — a disabled editor should not offer a switch its host would refuse.

renderTrailing appends your own node after a pill's label — one call per rendered pill, with null for the all-pill and the option's value for the rest. It is re-evaluated on every render, so the node follows whatever state the host is holding: a sort direction arrow, a count, a small badge.

TSX

API

Vue

Props

NameTypeDefaultRequired
labelString—✓
optionsArray as PropType<HkPillToggleGroupOption[]>() => []—
selectedObject as PropType<Set<string>>() => new Set<string>()—
allLabelStringundefined—
disabledBooleanfalse—
renderTrailing<code>Function as PropType<(value: string | null) => VNode | undefined></code>undefined—

Emits

EventPayload
togglestring
all—

Accessibility

  • The track is a role="group" whose accessible name is label — required, because a group of unlabelled pills says nothing about what it switches.
  • Each pill is a native <button type="button"> and publishes aria-pressed, so its on/off state is announced rather than inferred from the tint; the all-pill is a toggle in the same sense, pressed while nothing is picked.
  • Every pill is reachable with Tab and activates with Enter or Space; the track itself takes no focus, and panning is a pointer gesture that never removes a pill from the tab order.
  • Icons are decorative additions to the label: a pill's name is always its text, so an icon-only option is not expressible — give every option a label.
  • disabled sets the native disabled attribute on all pills, which takes them out of the tab order and tells assistive technology they are unavailable.

Related components

  • HkCheckbox — independent picks with a caption each.
  • HkRadio — one pick out of a short list.
  • HkSwitch — a single on/off in a form row.
  • HkSlider — one value along a continuous track.
  • HkSelect — a longer list that opens a surface.
  • HkButton — an action rather than a state.