Web and native

Chip in kanso-ui 0.59.0, for React.

import { Chip } from '@kanso-labs/kanso-ui'

A compact pill that is either a filter that toggles on and off, or an action.

It draws four of the Material Design chips: the filter chip (the default), the dropdown filter chip, and the assist and suggestion chips. The fourth, the input chip, is the removable chip a ChipGroup draws.

What you provide

  • children (required): the chip's label. A chip with none is an empty button to a screen reader.
  • For a set where only one may be selected, control each chip's isSelected yourself; a chip has no notion of its neighbours.

Props

PropTypeDefaultDescription
children requiredReactNode—The chip's label. A node rather than React Aria's node-or-function, since a filter chip puts its own check before whatever this is and a function would be handed a `defaultChildren` the chip never rendered. ChipGroup's chip narrows it the same way, for the same reason. Required: the page draws no chip without one, and a chip with none is an empty button to a screen reader.
elevatedbooleanfalseDeprecated: Kanso draws every chip outlined. The chip is drawn outlined whatever this says, and warns once in development.
iconReactNode—An icon before the label, in Kanso's 18px slot and the chip's own colour. On a filter chip the check takes its place while the chip is selected, so the chip keeps its width. An icon drawn in `em` takes its size from the slot.
isSelectedboolean—Draws the chip selected: the `ink` fill, and the check in front of the label. On a filter chip it is the toggle's state, announced through `aria-pressed`: pass it with `onChange` to control it. On a dropdown chip it is drawn only, for a menu that has a choice, and the chip's label is the place to name that choice.
trailingIconReactNode—An icon after the label, in the same 18px slot and the chip's own colour, which is the dropdown filter chip: an arrow here says the chip opens a menu. It stays while the chip is selected. An icon drawn in `em` takes its size from the slot.
variant required'assist' | 'suggestion'—

Also takes the props of Omit<ButtonProps, 'children' | 'isPending'>.

Example

import { Chip } from '@kanso-labs/kanso-ui'

<Chip defaultSelected>First filter</Chip>
<Chip variant="assist" icon={icon} onPress={run}>Label</Chip>
<Chip variant="suggestion">Label</Chip>

The design’s classes

k-chip, k-chip--input, k-chip__remove, k-chip--selected; aria-pressed or aria-checked on filter chips.

Maps to Chip, inside ChipGroup for a set, in kanso-ui and react-native-kanso-ui.