Skip to content
Nacre
Color palette
中文

ChoiceChip

experimentalChoiceChipOpen in playground
ChoiceChip
Runs the real component in your browser.

A set of short options where several can be picked, drawn as rounded chips: feedback reasons, interest tags. Reads as a checkbox and toggles with Space; the checked chip shows a checkmark on a subtle tint, and pressing only changes the fill, without scaling.

Status: experimental · Components: ChoiceChip

import { ChoiceChip } from 'nacre'

One chip per option, controlled with checked and onChange(checked), the same callback as CheckBox / CheckRow; lay a set out with flex-row flex-wrap gap-1.5. label is the text on the chip and its screen reader name.

import { Text, View, signal } from 'nsh'
import { ChoiceChip, TEXT_SIZE } from 'nacre'
const reasons = () => [
{ value: 'inaccurate', label: 'Inaccurate' },
{ value: 'incomplete', label: 'Incomplete' },
{ value: 'tone', label: 'Wrong tone' },
{ value: 'outdated', label: 'Outdated' },
]
export function ChoiceChipUsage() {
const picked = signal<string[]>(['incomplete'])
const toggle = (value: string, checked: boolean) => picked.update((list) => (checked ? [...list, value] : list.filter((v) => v !== value)))
return (
<View class="gap-2">
<View class="flex-row flex-wrap gap-1.5">
<Each of={reasons()} key={(r) => r.value}>
{(reason) => (
<ChoiceChip
testID={`choice-usage-${reason().value}`}
size="xs"
label={reason().label}
checked={picked().includes(reason().value)}
onChange={(checked) => toggle(reason().value, checked)}
/>
)}
</Each>
</View>
<Text testID="choice-usage-count" class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$Selected ${picked().length}`}</Text>
</View>
)
}

xs 24 for a set of reasons inside a form, sm 28 (default) on a row of its own; unchecked is an outline with secondary text, checked adds a checkmark on a subtle tint; disabled drops to 40% and ignores presses.

Phone: On phones the chips are 28 (xs) and 32 (sm) pills with a 44 tap area; unselected shows an outline and a plus, selected a tint, an accent outline and a check; disabled drops to 40%.

import { View, signal } from 'nsh'
import { ChoiceChip } from 'nacre'
export function ChoiceChipStates() {
const on = signal(true)
const off = signal(false)
return (
<View class="gap-3">
<View class="flex-row flex-wrap items-center gap-1.5">
<ChoiceChip testID="choice-sm-on" label="Account opening" checked={on()} onChange={(next) => on.set(next)} />
<ChoiceChip testID="choice-sm-off" label="Deposit" checked={off()} onChange={(next) => off.set(next)} />
<ChoiceChip testID="choice-sm-disabled" label="Withdrawal" checked={false} disabled onChange={() => {}} />
<ChoiceChip testID="choice-sm-disabled-on" label="Trading" checked disabled onChange={() => {}} />
</View>
<View class="flex-row flex-wrap items-center gap-1.5">
<ChoiceChip size="xs" label="Account opening" checked onChange={() => {}} />
<ChoiceChip size="xs" label="Deposit" checked={false} onChange={() => {}} />
<ChoiceChip size="xs" label="Withdrawal" checked={false} disabled onChange={() => {}} />
</View>
</View>
)
}
Key Action
Tab Each chip is one stop
Space Toggle
  • Reads as a checkbox named by label, reporting checked / not checked, and disabled when disabled.
  • A plus marks an available option and a checkmark marks a selection. Both icons have the same width so neighboring options stay in place.

Do

  • A set of short options where several can be picked (one to three words)
  • Wrap onto more rows when there are many
  • Use it in a form with a submit button

Don’t

  • Use it as a filter (use FilterChip)
  • Allow only one choice (use Segmented or RadioRow)
  • Settings that apply immediately (use Switch)
  • Put long sentences in it

Property descriptions follow the Chinese source comments.

Prop Type Default Description
label * string — 芯片上的字,也是读屏名
checked * boolean —
onChange * (checked: boolean) => void — 拿到点击后应有的新值(!checked),与 CheckBox / CheckRow 一致
disabled boolean —
size 'xs' | 'sm' 'sm' xs 24(表单里的一组原因、标签)/ sm 28(默认)
testID string —

* required