Chips
Web/MobileA row of selectable pills for filtering, tagging, or picking one or more options.
Installation
pnpm dlx cubix-ui@latest add chips --base ariaUsage
import { Chip, Chips } from "@/components/cubix/chips"
const categories = [
{ value: "electronics", label: "لوازم دیجیتال" },
{ value: "fashion", label: "پوشاک" },
{ value: "home", label: "خانه و آشپزخانه" },
{ value: "beauty", label: "زیبایی و سلامت" },
{ value: "books", label: "کتاب" },
]
<Chips defaultValue={["fashion"]} className="w-fit max-w-md justify-center">
{categories.map((category) => (
<Chip key={category.value} value={category.value}>
{category.label}
</Chip>
))}
</Chips>
Composition
Every Chip is a toggle inside a Chips group. Selection is tracked by value, the same string each chip passes. Pass icon or avatar for a leading visual, and onRemove for a remove button.
Chips
└── Chip
├── icon | avatar
└── remove button (with onRemove)Accessibility
Each chip is a toggle button that reports its state with aria-pressed. The group is a single tab stop; arrow keys move between chips and follow the reading direction, so they are mirrored in RTL. Removable chips are removed with Backspace or Delete, and focus moves to the neighboring chip. Give the remove button a specific name with removeLabel.
| Key | Action |
|---|---|
| Enter / Space | Toggle the focused chip. |
| Tab / Shift + Tab | Move to the next or previous focusable element on the page. |
| ArrowLeft / ArrowRight | Move focus to the next or previous enabled chip in reading direction, so the keys are mirrored in RTL. |
| Home / End | Move focus to the first or last enabled chip. |
| Backspace / Delete | Remove the focused chip when it has onRemove. Focus moves to the next chip, or the previous one at the end. |
Examples
Multiple
Set multiple to select any number of chips. Pass every selected value to defaultValue.
Controlled
Pass value and onValueChange to own the selected chips, for example to read or set the selection from outside.
انتخابشده: طراحی
Variants
Set variant on a Chip to pick how it looks when selected, using the same colors as Button. Unselected chips stay outlined.
Sizes
Set size on a Chip to use the same heights as Button. The default is sm.
With icon
Pass icon to show an icon at the inline start, hidden from assistive technology.
Removable
Pass onRemove to show a remove button. Remove the chip from your list and from the selection in the same handler.
Avatar
Pass an Avatar to avatar to show it in place of the icon. It scales with size.
Disabled item
Set disabled on a Chip to keep it visible but locked. Arrow key navigation skips it.
Disabled
Set disabled on Chips to lock every chip in its current state.
API Reference
Note: Parts render data-slot attributes (chips, chip, chip-root, chip-icon, chip-avatar, chip-remove) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.
Chips
| Prop | Type | Default | Description |
|---|---|---|---|
| multiple | boolean | false | Keep more than one chip selected. Without it, selecting a chip deselects the selected one, and the selected chip deselects itself. |
| value | string[] | - | Controlled selected chips. Use an array in both modes and pass at most one value in single mode. |
| defaultValue | string[] | - | Chips selected on first render when uncontrolled. |
| onValueChange | (value: string[]) => void | - | Called with the selected chips whenever a chip is toggled. |
| disabled | boolean | false | Disable every chip in the group. |
| dir | "ltr" | "rtl" | - | Text direction of the group. Defaults to the closest dir on the page. |
| lang | string | - | Language of the group. Defaults to the closest lang on the page. |
| className | string | - | Additional Tailwind classes merged with the root styles (last one wins). |
Chip
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Unique value used in value, defaultValue and onValueChange. Required. |
| icon | ReactNode | - | Icon rendered at the inline start, before the label, and hidden from assistive technology. |
| avatar | ReactNode | - | Avatar rendered at the inline start in place of the icon, sized to the chip. |
| variant | "default" | "secondary" | "gray" | "outline" | "default" | How the chip looks when selected, matching the Button variant of the same name. |
| size | "xs" | "sm" | "default" | "lg" | "sm" | Chip height, matching the Button size of the same name: 28, 32, 40 or 48px. |
| onRemove | () => void | - | Renders a remove button at the inline end and lets Backspace or Delete remove the focused chip. Removing does not change selection; update the value yourself. |
| removeLabel | string | "حذف" | Accessible name of the remove button. Include the chip label, for example حذف ریاکت. |
| disabled | boolean | false | Disable the chip and keep it in its current state. |
| className | string | - | Additional Tailwind classes merged with the chip styles (last one wins). |