Skip to main content

Chip

Pill control for filtering, multi-select, and removable tags.

import { Chip } from "@/fragments/ui";Source

Preview

import { Stack } from '@/components/Stack';

<Stack direction="row" gap="sm" wrap>
  <Chip>Soft</Chip>
  <Chip variant="outline">Outline</Chip>
</Stack>

Installation

npx @usefragments/cli add chip

Writes src/fragments/ui/components/Chip plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Anatomy

Chip is a compound: import the root and reach its parts through dot notation.

  • Chip.Group

Examples

Tones

The same ramp Badge and Button use, in both variants.

import { Stack } from '@/components/Stack';

<Stack direction="column" gap="sm">
  <Stack direction="row" gap="sm" wrap>
    <Chip tone="accent">Accent</Chip>
    <Chip tone="info">Info</Chip>

Sizes

xs for filter rows; larger sizes match taller field tracks.

import { Stack } from '@/components/Stack';

<Stack direction="row" gap="sm" align="center" wrap>
  <Chip variant="outline" size="xs">Extra small</Chip>
  <Chip variant="outline" size="sm">Small</Chip>
  <Chip variant="outline" size="md">Medium</Chip>

Selected

Both variants share one selection treatment.

import { Stack } from '@/components/Stack';

<Stack direction="row" gap="sm" wrap>
  <Chip selected>Soft</Chip>
  <Chip variant="outline" selected>Outline</Chip>
</Stack>

With Avatar

Leading face, for people-shaped selections.

<Chip avatar={<img src="https://i.pravatar.cc/32?u=chip" alt="" />}>
  Jane Doe
</Chip>

With Remove

Trailing dismiss button clears the tag.

import { Stack } from '@/components/Stack';

<Stack direction="row" gap="sm" wrap>
  <Chip variant="outline" onRemove={() => {}}>React</Chip>
  <Chip variant="outline" selected onRemove={() => {}}>TypeScript</Chip>
  <Chip tone="info" onRemove={() => {}}>SCSS</Chip>

Chip Group

Selection state is held by the group, not each chip.

<Chip.Group defaultValue={['react']}>
  <Chip value="react">React</Chip>
  <Chip value="vue">Vue</Chip>
  <Chip value="angular">Angular</Chip>
  <Chip value="svelte">Svelte</Chip>
</Chip.Group>

Chip Group with Custom Labels

Custom JSX children need an explicit value.

<Chip.Group aria-label="Assignees">
  <Chip value="jane">
    <span>Jane Doe</span>
  </Chip>
  <Chip value="sam">
    <span>Sam Lee</span>

Disabled

Dimmed and unreachable, selected or not.

import { Stack } from '@/components/Stack';

<Stack direction="row" gap="sm" wrap>
  <Chip variant="outline" disabled>Disabled</Chip>
  <Chip variant="outline" disabled selected>Disabled selected</Chip>
</Stack>

API

Component props
Prop
Type
Default
Description
childrenRequirednodeNot setChip label text
variantenumsoftoutlinesoftChrome family. soft is the tinted pill; outline is hairline-bordered on the page surface
toneenumneutralaccentinfosuccesswarningdangerneutralSemantic colour from the shared tone ramp. neutral is ink on the neutral surfaces; the others tint, border and ink from one derivation shared with Badge and Button
sizeenumxssmmdlg"xs"Chip size
selectedbooleanfalseWhether the chip is in a selected state
iconnodeNot setIcon element rendered before the label
avatarnodeNot setAvatar element rendered before the label
onRemovefunctionNot setMakes chip removable. Called when X is clicked.
valuestringNot setValue identifier used by Chip.Group for selection tracking
disabledbooleanfalse
onClickfunctionNot set

Accessibility

  • Chips are buttons; selection is reported via aria-pressed
  • Add role and aria-label to Chip.Group when the set needs a name
  • Remove buttons carry the chip text in their aria-label
  • Disabled chips are skipped by keyboard and pointer

Guidance

Use when

  • Filtering a list by tag or category
  • Multi-select from a compact set
  • Showing filters the user can dismiss

Avoid when

  • Read-only status — use Badge
  • Switching views — use Tabs
  • On/off state — use Switch
  • A main call to action — use Button
  • BadgesiblingBadge is display-only; Chip is interactive
  • ToggleGroupalternativeUse ToggleGroup for mutually exclusive options
  • ButtonalternativeUse Button for primary actions, Chip for selection/filtering

Next steps