Chip group

Free

A row of filter chips with counts: press one and it fills with the accent tint, and the total beside it rolls only the digits that changed.

npx shadcn@latest add https://pixilui.com/r/chip-group.json

Preview

Press a filter and only the changed digits of the total roll.
Mode
Size

When to use

Use it when

  • Filtering a list of runs, tickets or sources by a few known groups, with a count on each.
  • A single choice among a few short options that read as filters (single).
  • Showing how many results the filters leave, with ChipGroupTotal in the sentence beside it.

Use something else when

  • Switching between views of the same thing: use a segmented control or tabs.
  • Many options or a search: use a menu or a select.
  • Context attached to a prompt: use Chip in a ChipRow.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/chip-group.json

Adds chip-group.tsx with chip.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { ChipGroup } from "@/components/pixilui/chip-group";

<ChipGroup
  aria-label={aria-label}
  options={options}
  onValueChange={onValueChange}
/>

The chips wrap; the total sits in its own sentence and wraps with it.

API reference

PropTypeDefault
aria-labelRequiredstring–The group's accessible name, such as "Filter runs".
optionsRequiredChipGroupOption[]NONEThe filters, in order.
valuestring[]–Controlled: the values that are on.
defaultValuestring[]–Starting values when uncontrolled (defaults to the all chip, if there is one).
onValueChange(value: string[], total: number) => void–Runs with the values that are on and the total of their counts.
singlebooleanfalseOne at a time.
size"md" | "sm""md"md 30 (the default), sm 26.

Also takes every native <div> attribute except onChange, defaultValue, and a ref.

Keyboard

TabMoves through the filter chips in order.
Enter SpacePresses or releases the focused filter.

Accessibility

  • The group is role="group" named by its aria-label, such as "Filter runs".
  • Each filter is a button with aria-pressed.
  • The all chip clears the others and comes back on its own when none is pressed.
  • Put ChipGroupTotal inside a sentence ("Showing 12 runs") and give that sentence aria-live="polite" if the count should be announced.

Motion

  • A pressed chip takes the accent tint, ring and deep accent words in 150ms.
  • The total rolls only the digits that changed, up and out, in 350ms on the out curve; a digit that leaves narrows its slot and one that arrives widens it, all on the text's baseline.
  • Reduced motion: the number swaps at once.
ChipA removed chip folds away while the row closes the gap.
Segmented controlThe pill slides to your pick; a time-boxed choice says when it ends and switches back.
BadgeSolid icons cut from the outlines, in the locked status colors.

PixilUI Pro opens soon. The first 20 licenses are $99.