Documentation

Chip

A selectable pill: alone a toggle, in a group a single or multiple choice, or a removable tag.

Web + MobileBetaForms

Web and mobile — the same component for React and React Native. Beta: its API may still change in a minor version.

When to use

  • To filter a list with a few short options shown at once: format, genre, speed.
  • Chip.Group type="multiple" for several tags; type="single" (with required) for one filter.
  • removable for the values already chosen: tags, recipients, active filters.

When not to use

  • To switch between views of the same page.Use instead: Tabs
  • To choose in a form that is submitted, with labels that read as sentences.Use instead: Radio group
  • For a status that cannot be changed.Use instead: Badge
  • To run an action.Use instead: Button

Installation

Install

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { Chip } from "@krizaka/ui/chip";

Examples

Toggle

Alone, off and on: a pressed button.

Single choice

One choice in a group: a filter; required keeps one chosen.

Multiple choice

Several choices: tags.

Small

size="sm" for dense toolbars.

Removable

Chosen tags, each with a named remove button.

#night#city

Props

Chip

Chip (selectable, removable) and Chip.Group (single · multiple).

PropTypeDefaultDescription
onRemoverequired() => void—Runs when the remove button is pressed.
removeLabelrequiredstring—The accessible name of the remove button — passed translated, e.g. "Remove #night".
defaultSelectedboolean—Alone: pressed at first, uncontrolled.
onSelectedChange((selected: boolean) => void)—Alone: called with the new state on every press.
removableboolean—A pressable chip (the default); true makes it a static chip with a remove button. A static chip (a chosen tag, an applied filter) with a remove button.
selectedboolean—Alone: pressed or not (defaultSelected uncontrolled), onSelectedChange on every press.
size"sm" | "md"mdsm · md (inside Chip.Group, the group's size by default).
valuestring—Inside Chip.Group: the value this chip stands for (required there, ignored alone).

ChipGroup

Chips that choose together: type single · multiple, value/defaultValue + onValueChange.

PropTypeDefaultDescription
typerequired"single" | "multiple"—One choice: the chips behave as radios. Any number of choices: the chips are pressed buttons.
defaultValuestring | string[]—The value chosen at first, uncontrolled. The values chosen at first, uncontrolled.
disabledboolean—Disables every chip of the group.
labelstring—The group's accessible name — passed translated ("Filter by format").
loopboolean—Arrow keys wrap from the last chip to the first (default true).
onValueChange((value: string) => void) | ((value: string[]) => void)—Called with the new value on every choice. Called with the new values on every press.
orientation"horizontal" | "vertical"—The arrow keys that move: left / right (horizontal, a row) or up / down (vertical, a column).
requiredboolean—Keeps one chip selected: pressing the selected chip does not clear it (default false).
size"sm" | "md"mdsm · md: the size of every chip of the group.
valuestring | string[]—The chosen value (controlled), "" when none. The chosen values (controlled).

Accessibility

  • Radix Toggle and ToggleGroup: alone aria-pressed; in a single group a radio (aria-checked), in a multiple group pressed buttons.
  • Chip.Group takes label as the group's accessible name.
  • The remove button is a separate button named by removeLabel.

Keyboard

KeysAction
TabMoves into the group (one tab stop) and out of it.
Arrow keysMove between the chips of a group.
Space / EnterToggles the focused chip.

Best practices

  • One or two words per chip; the group's label says what is being chosen.
  • Keep the order stable when a chip is selected: do not move it to the front.
  • Give each removable chip a removeLabel that names it: “Remove #night”, not “Remove”.

Generated from the code of @krizaka/ui 2.0.0-beta.6: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page