Recipes
Chips
Chips split by interaction - action chips are small Buttons, choice and filter chips a chip-variant ToggleButtonGroup, input chips a TagGroup.
Chips are built from the building block that matches what the chips do.
| Chips | Build them with |
|---|---|
| Action chips (click handlers) | Button size="sm" (optionally variant="chip" or "outline") |
| Choice chips (one selected) | ToggleButtonGroup variant="chip" |
| Filter chips (several selected) | ToggleButtonGroup variant="chip" selectionMode="multiple"; a pressed chip shows a check |
| Chips without selection | Chip-styled Buttons in a ButtonGroup attached={false} |
| A single chip | A chip-styled Button or ToggleButton |
| Input chips (delete, add, drag) | TagGroup |
Choice, filter and action chips
Open demoSingle-selection choice chips, multiple-selection filter chips with a check mark, and action chips in a spaced button group.
Active filters: Open
Data, content and state
- Each chip is a
ToggleButtonchild with its text and avalue; map your data in JSX. - The selection is
value/defaultValue, by value only, since indexes are not stable. - Avatars, leading and trailing icons are
iconStart/iconEndnodes. disabledgoes on the group or the item;classNameand other attributes go on each item.- Clicks are the item's
onClick; to cancel a selection, keepvaluecontrolled and ignore the proposal. toneandvarianton the group or the item set the style; states aredata-pressed/aria-checked,:focus-visibleanddisabled.- Keys are the toggle group keys: arrows move (and select in single mode), Space / Enter select or toggle.
import { ToggleButton, ToggleButtonGroup } from '@salmonui/buttons/button';
import '@salmonui/buttons/button/styles.css';
<ToggleButtonGroup aria-label="Assignees" variant="chip" selectionMode="multiple" value={ids} onValueChange={setIds}>
{people.map((person) => (
<ToggleButton key={person.id} value={person.id} disabled={person.away} iconStart={<Avatar person={person} />}>
{person.name}
</ToggleButton>
))}
</ToggleButtonGroup>;
Chips from data
Open demoFilter chips mapped from application data with avatar and trailing content, per-chip tone, class, attributes and disabled state, a group-wide disable, a click veto through the controlled value, and single chips.
Selected: · Starred only:
Recent clicks:
Design notes
- There are no imperative select or find methods: read and set the
selection through the controlled
valueand your own data. - The group is one tab stop with roving focus, so a long chip list does not flood the tab order.
- Chips use toggle semantics, not
listbox/option:radiogroup/radiowitharia-checked(single) orgroupwitharia-pressed(multiple); listbox semantics are left toListbox, and input chips are aTagGroupgrid. - Input chips are TagGroup:
onRemoveadds a remove button and Delete / Backspace, cancelling a removal is a controlled update you skip, adding and removing are changes to your array,reorderableanddragGroupwithonTagDragStart/onTagDrag/onTagDragEndhandle drag and drop, and removable tags carryaria-keyshortcuts.