- Docs
- Components
- Data display
Chip
An interactive tag: one that turns on and off, such as a filter, or a choice already made with a button that removes it.
- Import
- @qeetrix/react/experimental
- Status
- ExperimentalSince 0.4.0
- Renders
<span role="checkbox">Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// Experimental: from the package's experimental entry, until it's stable.
import { Chip, ChipGroup } from "@qeetrix/react/experimental";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
children | ReactNode | required | The label. A string also names a removable chip's remove button. |
icon | IconSource | — | A 16px sharp icon before the label; a selectable chip with one shows no check. |
size | "sm" | "md" | "lg" | "md", or the group's | The controls' heights: sm for a filter row over a list, lg the fields'. |
checked · defaultChecked | boolean | — · false | Selectable: on or off, as Base UI's Checkbox. Not in a one-value ChipGroup, whose value says which. |
onCheckedChange | (checked, details) => void | — | Called with the new state. |
value | string | — | In a ChipGroup, the value it stands for. |
disabled | boolean | false | Greys it; on a removable chip, its remove button too. |
onRemove | () => void | — | Makes it removable: a static label ending in a remove button. Taking it away, and moving focus, is yours. |
removeLabel | string | "Remove {label}" | The remove button's name, for a label that isn't plain text. |
messages | { remove?, removePlain? } | the provider's | A removable chip's strings: "Remove {label}", and "Remove" for a label that isn't text. |
ChipGroup: label | string | required | Names the group for assistive technology, "Status". It isn't shown. |
ChipGroup: multiple | boolean | false | Several values, the chips checkboxes; otherwise one, the chips radios. |
ChipGroup: value · defaultValue | string, or string[] with multiple | — | The chosen value, or values, as Base UI's RadioGroup and CheckboxGroup. |
ChipGroup: onValueChange | (value, details) => void | — | Called with the new value, or values. |
ChipGroup: size | "sm" | "md" | "lg" | "md" | Every chip's size. |
ChipGroup: disabled | boolean | false | Disables every chip. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
chip-group | <div role="radiogroup"> | role="group" with multiple; aria-label from label. |
chip | <span role="checkbox"> | role="radio" in a one-value group; aria-checked, data-checked, data-size. A removable chip is a <span> with data-removable. |
chip-check | <span> | The check, while chosen, without an icon. |
chip-icon | <svg> | The icon, aria-hidden. |
chip-label | <span> | The label. |
icon-button | <button> | A removable chip's remove button: aria-label "Remove {label}". |
04
Filters over a list
A one-value group, sm, in the toolbar of the table it filters.
const [status, setStatus] = useState("all");
const shown = status === "all" ? users : users.filter((user) => user.status === status);
<Table
label="Users"
rows={shown}
columns={columns}
rowId={(user) => user.id}
rowLabel={(user) => user.name}
toolbar={
<ChipGroup label="Status" size="sm" value={status} onValueChange={setStatus}>
<Chip value="all">All</Chip>
<Chip value="active">Active</Chip>
<Chip value="invited">Invited</Chip>
</ChipGroup>
}
/>05
In a form
A one-value group posts its value under name. With multiple, give each chip the name: the group takes none.
<ChipGroup label="Plan" name="plan" defaultValue="growth">…</ChipGroup>
<ChipGroup label="Departments" multiple defaultValue={["eng"]}>
<Chip name="departments" value="eng">Engineering</Chip>
<Chip name="departments" value="fin">Finance</Chip>
</ChipGroup>06
A bar of applied filters
Tags under a toolbar with Clear all, a summary of what's left, and focus moved for you: FilterTags.
import { FilterTags } from "@qeetrix/react/experimental";
<FilterTags
filters={[{ id: "status", label: "Status", value: "Active" }]}
onRemove={removeFilter}
onClear={clearFilters}
summary="412 of 1,284 users"
/>