Chip
Chips help people enter information, make selections, filter content, or trigger actions.
Chips help people enter information, make selections, filter content, or trigger actions. They appear together as a group, in a row of options.
For an action that stands alone, use a button instead.
Chips are written in a group, with these parts:
| Part | Use |
|---|---|
ChipGroup | The group, which lays out its chips in rows and sets whether they act, select or are removed. See Chip actions. |
Chip | A chip, whose variant sets its type |
import { Chip, ChipGroup, Icon, IconButton } from '@material-web/react'
import { Text } from 'react-aria-components'Basic chip
Put each Chip in a ChipGroup, and write the chip's label as its children. A Chip outside a ChipGroup throws an error. The group lays out its chips in rows that wrap onto the next line.
import { Chip, ChipGroup, Icon } from '@material-web/react'
const diets = ['Vegan', 'Gluten free', 'Organic', 'Local']
export default function Basic() {
return (
<ChipGroup aria-label="Diet" selectionMode="multiple" defaultSelectedKeys={['vegan']}>
{diets.map((diet) => (
<Chip key={diet} id={diet.toLowerCase()} variant="filter" textValue={diet}>
{({ isSelected }) => (
<>
{isSelected && <Icon slot="leading" name="check" />}
{diet}
</>
)}
</Chip>
))}
</ChipGroup>
)
}A chip is named by its textValue. A chip whose children are a plain string uses that string as its textValue. Any other chip requires a textValue: one whose children are a function, or hold an icon or a Text label.
The Chip comes in four variants. Set variant to assist, filter, input or suggestion. It is required and has no default.
import { Chip, ChipGroup, Icon } from '@material-web/react'
export default function Variants() {
return (
<ChipGroup aria-label="Variants">
<Chip id="assist" variant="assist" textValue="Assist">
<Icon slot="leading" name="event" />
Assist
</Chip>
<Chip id="filter" variant="filter" textValue="Filter">
Filter
<Icon slot="trailing" name="arrow_drop_down" />
</Chip>
<Chip id="input" variant="input" textValue="Input">
<Icon slot="leading" name="person" />
Input
</Chip>
<Chip id="suggestion" variant="suggestion">
Suggestion
</Chip>
</ChipGroup>
)
}Assist chip
Assist chips represent smart or automated actions that can span multiple apps. Handle a press with onAction on the chip, or with onAction on the group, which is called with the id of the chip.
No action yet
import { Chip, ChipGroup, Icon } from '@material-web/react'
import { useState } from 'react'
import type { Key } from 'react-aria-components'
export default function Assist() {
const [action, setAction] = useState<Key>()
return (
<div className="flex flex-col items-center gap-space-200">
<ChipGroup aria-label="Actions" onAction={setAction}>
<Chip id="calendar" variant="assist" textValue="Add to calendar">
<Icon slot="leading" name="event" />
Add to calendar
</Chip>
<Chip id="directions" variant="assist" textValue="Get directions">
<Icon slot="leading" name="directions" />
Get directions
</Chip>
<Chip id="share" variant="assist" textValue="Share">
<Icon slot="leading" name="share" />
Share
</Chip>
</ChipGroup>
<p className="m-0 text-body-md text-on-surface-variant">
{action ? `Last action: ${action}` : 'No action yet'}
</p>
</div>
)
}Filter chip
Filter chips represent filters for a collection. Set selectionMode on the group to single or multiple, and give each chip an id. Control the selection with selectedKeys and onSelectionChange, or set the initial selection with defaultSelectedKeys. See React Aria's Selection guide.
A selected filter chip has no checkmark unless you add one: put an Icon in the leading slot while the chip isSelected, as in this example.
import { Chip, ChipGroup, Icon } from '@material-web/react'
import { useState } from 'react'
import type { Selection } from 'react-aria-components'
const orders = ['Price', 'Rating', 'Distance']
export default function Filter() {
const [selected, setSelected] = useState<Selection>(new Set(['price']))
return (
<div className="flex flex-col items-center gap-space-150">
<span id="sort-by" className="text-title-sm text-on-surface">
Sort by
</span>
<ChipGroup
aria-labelledby="sort-by"
selectionMode="single"
selectedKeys={selected}
onSelectionChange={setSelected}
>
{orders.map((order) => (
<Chip key={order} id={order.toLowerCase()} variant="filter" textValue={order}>
{({ isSelected }) => (
<>
{isSelected && <Icon slot="leading" name="check" />}
{order}
</>
)}
</Chip>
))}
</ChipGroup>
</div>
)
}Input chip
Input chips represent discrete pieces of information entered by a person. Handle their removal with onRemove on the group. It is called with the ids of the chips to remove when a chip's remove button is pressed, or on Backspace or Delete on a chip.
Add the remove button as an IconButton with slot="remove". It is named by its aria-label and the chip's label. A Button from react-aria-components with slot="remove" is named Remove, in the current locale, unless you set an aria-label.
import { Chip, ChipGroup, Icon, IconButton } from '@material-web/react'
import { Text, useListData } from 'react-aria-components'
export default function Input() {
const people = useListData({
initialItems: [
{ id: 'ann', name: 'Ann Lee' },
{ id: 'bo', name: 'Bo Chen' },
{ id: 'cy', name: 'Cy Park' },
],
})
return (
<ChipGroup
aria-label="Recipients"
items={people.items}
onRemove={(keys) => people.remove(...keys)}
renderEmptyState={() => (
<span className="text-body-md text-on-surface-variant">No recipients</span>
)}
>
{(person) => (
<Chip variant="input" textValue={person.name}>
<Icon slot="leading" name="person" />
<Text slot="label">{person.name}</Text>
<IconButton slot="remove" aria-label="Remove">
<Icon name="close" />
</IconButton>
</Chip>
)}
</ChipGroup>
)
}In this example, a function renders the chips from the group's items, and renderEmptyState renders what the group shows after the last chip is removed. See Chip array.
Suggestion chip
Suggestion chips help narrow a person's intent by presenting dynamically generated suggestions, such as what to say or search next. Handle a press with onAction, as on an assist chip.
Nothing asked yet
import { Chip, ChipGroup } from '@material-web/react'
import { useState } from 'react'
import type { Key } from 'react-aria-components'
const questions = ['What song is this?', 'What are the lyrics?', 'Who is the artist?']
export default function Suggestion() {
const [asked, setAsked] = useState<Key>()
return (
<div className="flex w-full max-w-96 flex-col gap-space-200">
<ChipGroup aria-label="Suggestions" onAction={setAsked}>
{questions.map((question) => (
<Chip key={question} id={question} variant="suggestion">
{question}
</Chip>
))}
</ChipGroup>
<p className="m-0 text-body-md text-on-surface-variant">
{asked ? `Asked: ${asked}` : 'Nothing asked yet'}
</p>
</div>
)
}Elevated chip
Set isElevated to give a chip its own container with a shadow. Use it for a chip that needs more visual separation, such as on an image or a dynamic background. An input chip is always flat, and its types do not accept isElevated.
import { Chip, ChipGroup, Icon } from '@material-web/react'
export default function Elevated() {
return (
<div className="rounded-shape-lg bg-tertiary-container p-space-600">
<ChipGroup aria-label="Elevated" selectionMode="multiple" defaultSelectedKeys={['filter']}>
<Chip id="assist" variant="assist" isElevated textValue="Assist">
<Icon slot="leading" name="event" />
Assist
</Chip>
<Chip id="filter" variant="filter" isElevated textValue="Filter">
{({ isSelected }) => (
<>
{isSelected && <Icon slot="leading" name="check" />}
Filter
</>
)}
</Chip>
<Chip id="suggestion" variant="suggestion" isElevated>
Suggestion
</Chip>
</ChipGroup>
</div>
)
}Slots
- leading
- label
- trailing
- remove
| Slot | Child | Use |
|---|---|---|
leading | An Icon or an image | Before the label, on every chip. See Avatars and Icons. |
label | A Text | The label, on every chip. See Long labels. |
trailing | An Icon or a button | After the label, on a filter chip. See Trailing button. |
remove | A button | The remove button, after the label, on an input chip. An input chip has no trailing slot. |
Set slot on a child to place it in one of the chip's slots. A child is placed by its slot, in whatever order the children are written. See Slots.
Note: An Icon or a button with a slot that its chip does not have throws an Invalid slot error, and so does a button with no slot. Any other element with another slot is shown where it is written, and so is an Icon with no slot.
Avatars
Put an image in a chip to show an avatar, in the leading slot or with no slot. It is shown round, at the start of the chip.
import { Chip, ChipGroup, Icon, IconButton } from '@material-web/react'
import { Text, useListData } from 'react-aria-components'
const avatar = (initial: string, color: string) =>
`data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><rect width="48" height="48" fill="${color}"/><text x="24" y="32" font-family="sans-serif" font-size="24" fill="white" text-anchor="middle">${initial}</text></svg>`,
)}`
export default function Avatar() {
const people = useListData({
initialItems: [
{ id: 'ann', name: 'Ann Lee', avatar: avatar('A', '#6750a4') },
{ id: 'bo', name: 'Bo Chen', avatar: avatar('B', '#386a20') },
],
})
return (
<ChipGroup aria-label="Guests" items={people.items} onRemove={(keys) => people.remove(...keys)}>
{(person) => (
<Chip variant="input" textValue={person.name}>
<img slot="leading" alt="" src={person.avatar} />
<Text slot="label">{person.name}</Text>
<IconButton slot="remove" aria-label="Remove">
<Icon name="close" />
</IconButton>
</Chip>
)}
</ChipGroup>
)
}Icons
Put an icon in the leading or trailing slot. An Icon is sized and colored for the chip, unless a class on the icon sets its own size or color. Any icon works in a slot.
import { Chip, ChipGroup, Icon, IconButton } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'
export default function Slots() {
const [price, setPrice] = useState('Under $50')
return (
<ChipGroup aria-label="Slots">
<Chip id="leading" variant="assist" textValue="Leading icon">
<Icon slot="leading" name="event" />
Leading icon
</Chip>
<Chip id="trailing" variant="filter" textValue="Trailing icon">
Trailing icon
<Icon slot="trailing" name="arrow_drop_down" />
</Chip>
<Chip id="both" variant="filter" textValue="Both">
<Icon slot="leading" name="sell" />
Both
<Icon slot="trailing" name="arrow_drop_down" />
</Chip>
<Chip id="price" variant="filter" textValue={price}>
<Text slot="label">{price}</Text>
<IconButton slot="trailing" aria-label="Clear price" onPress={() => setPrice('Any price')}>
<Icon name="close" />
</IconButton>
</Chip>
</ChipGroup>
)
}Trailing button
A chip can hold a button after its label. On an input chip, it is the remove button, with slot="remove". On a filter chip, it is any button with slot="trailing": give it its own aria-label and onPress, as on the last chip of the example above. It is disabled with the chip. An assist or suggestion chip takes no button.
Chip array
Write the chips as the group's children, or pass items with a function as children that returns a chip for each item, as with React Aria's collections. The group also accepts dependencies for that function, and renderEmptyState for the content of an empty group.
In this example, both groups render their chips from an array in state. Removing a chip takes it out of the first array, and pressing a suggestion adds it.
import { Chip, ChipGroup, Icon, IconButton } from '@material-web/react'
import { useState } from 'react'
import { Text } from 'react-aria-components'
const toppings = [
{ id: 'basil', name: 'Basil' },
{ id: 'garlic', name: 'Garlic' },
{ id: 'olives', name: 'Olives' },
{ id: 'peppers', name: 'Peppers' },
{ id: 'onions', name: 'Onions' },
]
export default function ChipArray() {
const [added, setAdded] = useState(toppings.slice(0, 2))
const others = toppings.filter((topping) => !added.includes(topping))
return (
<div className="flex w-full max-w-96 flex-col gap-space-200">
<ChipGroup
aria-label="Toppings"
items={added}
onRemove={(keys) => setAdded(added.filter((topping) => !keys.has(topping.id)))}
renderEmptyState={() => (
<span className="text-body-md text-on-surface-variant">No toppings</span>
)}
>
{(topping) => (
<Chip variant="input" textValue={topping.name}>
<Text slot="label">{topping.name}</Text>
<IconButton slot="remove" aria-label="Remove">
<Icon name="close" />
</IconButton>
</Chip>
)}
</ChipGroup>
<ChipGroup
aria-label="More toppings"
items={others}
onAction={(id) => setAdded([...added, toppings.find((topping) => topping.id === id)!])}
>
{(topping) => (
<Chip variant="suggestion" textValue={topping.name}>
<Icon slot="leading" name="add" />
{topping.name}
</Chip>
)}
</ChipGroup>
</div>
)
}A chip takes the id of its item unless you set one. For the ids, the text values and dependencies, see Collections. To keep the array in state with methods that add and remove items, use React Aria's useListData, as the input chips do.
Chip actions
What the chips do is set on their group: the chips of a group act, select or are removed together.
| Action | Set on the ChipGroup | Keyboard | Example |
|---|---|---|---|
| Act on a press | onAction, called with the id of the chip | Enter | Assist chip |
| Select | selectionMode, with selectedKeys and onSelectionChange | Space or Enter | Filter chip |
| Remove | onRemove, with a remove button in each chip | Backspace or Delete | Input chip |
Only filter and input chips show selection.
Selectable and removable chips
Set both selectionMode and onRemove on a group for chips that can be selected and removed. Backspace or Delete on a selected chip removes every selected chip.
import { Chip, ChipGroup, Icon, IconButton } from '@material-web/react'
import { Text, useListData } from 'react-aria-components'
export default function SelectableRemovable() {
const tags = useListData({
initialItems: [
{ id: 'travel', name: 'Travel' },
{ id: 'food', name: 'Food' },
{ id: 'music', name: 'Music' },
{ id: 'film', name: 'Film' },
],
})
return (
<ChipGroup
aria-label="Tags"
items={tags.items}
selectionMode="multiple"
onRemove={(keys) => tags.remove(...keys)}
>
{(tag) => (
<Chip variant="input" textValue={tag.name}>
<Text slot="label">{tag.name}</Text>
<IconButton slot="remove" aria-label="Remove">
<Icon name="close" />
</IconButton>
</Chip>
)}
</ChipGroup>
)
}Disabled
Disable a chip with its own isDisabled, or with disabledKeys on the group. A disabled chip cannot be selected or removed, and a button in it is disabled too.
import { Chip, ChipGroup, Icon } from '@material-web/react'
export default function Disabled() {
return (
<ChipGroup aria-label="Disabled" selectionMode="multiple" disabledKeys={['filter']}>
<Chip id="assist" variant="assist" isDisabled textValue="Assist">
<Icon slot="leading" name="event" />
Assist
</Chip>
<Chip id="filter" variant="filter">
Filter
</Chip>
<Chip id="suggestion" variant="suggestion" isElevated isDisabled>
Suggestion
</Chip>
<Chip id="enabled" variant="filter">
Enabled
</Chip>
</ChipGroup>
)
}Color
A variant sets the chip's colors. To use other color roles, pass their classes in className, with a state variant for the colors of a state. In this example, a selected chip takes the tertiary container colors in place of the secondary ones.
import { Chip, ChipGroup, Icon } from '@material-web/react'
const genres = ['Jazz', 'Soul', 'Funk', 'Disco']
export default function Colors() {
return (
<ChipGroup aria-label="Genres" selectionMode="multiple" defaultSelectedKeys={['jazz', 'funk']}>
{genres.map((genre) => (
<Chip
key={genre}
id={genre.toLowerCase()}
variant="filter"
textValue={genre}
className="selected:bg-tertiary-container selected:text-on-tertiary-container"
>
{({ isSelected }) => (
<>
{isSelected && <Icon slot="leading" name="check" />}
{genre}
</>
)}
</Chip>
))}
</ChipGroup>
)
}Long labels
The label of a chip is one line. Write it as the chip's text, or as a Text with slot="label":
- A
Textlabel is cut short with an ellipsis in a chip too narrow for it. A chip is never wider than its group. - A
Textlabel takes the free room of a wider chip, keeping what follows it at the end. - A label written as plain text is not cut short, and overflows a chip too narrow for it.
import { Chip, ChipGroup, Icon } from '@material-web/react'
import { Text } from 'react-aria-components'
export default function LongLabel() {
return (
<div className="w-64">
<ChipGroup aria-label="Filters">
<Chip id="distance" variant="filter" textValue="Within 25 kilometers of the city center">
<Text slot="label">Within 25 kilometers of the city center</Text>
<Icon slot="trailing" name="arrow_drop_down" />
</Chip>
<Chip id="price" variant="filter" textValue="Any price" className="w-full">
<Text slot="label">Any price</Text>
<Icon slot="trailing" name="arrow_drop_down" />
</Chip>
</ChipGroup>
</div>
)
}Links
Give a chip an href to make it a link, with target and rel as on an <a>. A press follows the link, and does not select the chip. The chip is not rendered as an <a> element.
import { Chip, ChipGroup, Icon } from '@material-web/react'
const pages = ['Overview', 'Specs', 'Guidelines']
export default function LinkChips() {
return (
<ChipGroup aria-label="Material Design pages on chips">
{pages.map((page) => (
<Chip
key={page}
id={page}
variant="assist"
textValue={page}
href={`https://m3.material.io/components/chips/${page.toLowerCase()}`}
target="_blank"
rel="noreferrer"
>
<Icon slot="leading" name="open_in_new" />
{page}
</Chip>
))}
</ChipGroup>
)
}To send these links through a client-side router, wrap the app in RouterProvider from react-aria-components. See Routing.
Customization
Pass classes in className to restyle one chip. A class of yours replaces the chip's own class for the same property. See Styling for the classes, the states and the theme.
import { Chip, ChipGroup, Icon } from '@material-web/react'
const sizes = ['Small', 'Medium', 'Large']
export default function Custom() {
return (
<ChipGroup
aria-label="Size"
selectionMode="single"
defaultSelectedKeys={['medium']}
className="density-2"
>
{sizes.map((size) => (
<Chip
key={size}
id={size.toLowerCase()}
variant="filter"
textValue={size}
className="rounded-shape-full"
>
{({ isSelected }) => (
<>
{isSelected && <Icon slot="leading" name="check" />}
{size}
</>
)}
</Chip>
))}
</ChipGroup>
)
}- Density: Add
density-1,density-2ordensity-3to the group, or to an element around it. Each step makes its chips 4dp shorter than their 32dp, and their targets stay 48dp. Set it on the group and not on one chip: the chips of a row are as tall as the tallest one. See Density. - States: Style a state with its variant, such as
hover:,pressed:orselected:. See States. - Every chip: To restyle all the chips at once, change the theme.
Children as a function
Pass a function as children to render a chip from its state: isHovered, isPressed, isFocused, isFocusVisible, isSelected, isDisabled, allowsRemoving, selectionMode and selectionBehavior. The function can fill the chip's slots too, as the checkmark of a filter chip does above. The function must be the only child. To return several children, wrap them in a fragment. See Children as a function.
Note: isHovered is reported only for a chip that selects or acts. For a chip with a remove button, it is reported while the pointer is anywhere on the chip, including that button.
className and style can be functions of the same state. The state's type is exported as ChipRenderProps. On a ChipGroup with items, the children are a function that returns a chip for each item.
Use cases
Material lists what people should be able to do with assistive technology:
- Use a chip to perform an action
- Navigate to a chip
- Activate a chip
Interaction and style
- States: A chip that selects or acts shows a state layer on hover, and a press shows a ripple. A chip that does neither shows no hover layer. Keyboard focus shows a focus ring, and a press with a mouse or touch does not. A remove button shows a focus ring of its own.
- Touch target: Every chip has a touch target of at least 48dp, and a remove button has a 48dp target of its own, above the chip's. A group keeps its chips 8dp apart, and its rows 16dp apart, where their targets meet.
- Color contrast: A chip's label needs 3:1 contrast with the background. Keep that contrast when you change its colors.
- Density: Each density step makes a chip 4dp shorter, and its target stays 48dp. Material advises applying density only when people choose it, such as with a denser layout setting.
- Motion: With reduced motion, the changes of color and shadow are instant.
- Forced colors: In forced colors, every chip keeps an edge, and a selected filter or input chip is filled with the system's highlight color.
- Horizontal overflow: A group wraps its chips onto as many rows as they need, so that every chip shows without scrolling, as Material advises. To show one row at first, add a Show all filter chip that shows the rest, or a leading button that lists them in a menu. Don't list chips that have a remove button in a menu.
- Interactivity: Material requires a second cue that chips are interactive. Use one of these: a label before the group, such as Select type, which can name the group with
aria-labelledby; page context, such as Filter results; an outline in theoutlinerole for 3:1 contrast, withinset-ring-outlinein a flat chip'sclassName; or a label or leading icon that suggests an action, such as Turn on lights.
Focus
- The group is one tab stop. Tab moves the focus to the chip that was focused last, and then to that chip's remove button.
- When the focused chip is removed, the focus moves to the next chip, to the previous one if it was the last, or to the group if no chip is left.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus into the group, to the chip focused last, and then to that chip's remove button |
| Arrow keys | Move the focus to the previous or next chip, wrapping at the ends |
| Home | Move the focus to the first chip |
| End | Move the focus to the last chip |
| Space or Enter | Select the focused chip, or deselect a selected one, in a group that selects |
| Escape | Deselect every chip, in a group that selects |
| Enter | Act on the focused chip, in a group that acts |
| Backspace or Delete | Remove the focused chip, or every selected chip if it is selected, in a group with onRemove |
- In a group that acts, Space does not act on the focused chip.
- The direction of the Left and Right arrow keys follows the locale set with
I18nProvider, not the page'sdir.
Labeling elements
- The group has the grid role, and each chip is a row in it. Name the group with an
aria-labelor anaria-labelledby. - A chip is named by its label text, as Material advises. Label additional actions, such as remove, separately, and hide images: an
Iconin a chip is hidden from assistive technology, and an avatar needs an emptyalt. - A chip whose children are not a plain string takes its name from
textValue. See Basic chip. - Material advises a remove button on every chip that can be removed. Its name is its
aria-label, or Remove in the current locale, followed by the chip's label, such as Remove Ann. See Input chip. - In a group that selects, a chip reports whether it is selected with
aria-selected. - In a group with
onRemove, a chip focused with the keyboard or a screen reader has a description that tells how to remove it with Delete, in the current locale. - While the focus is in the group, screen readers announce chips added to it.
ChipGroup
Props of ChipGroup (25)
classNamestringDefault'react-aria-TagGroup'The CSS className for the element.
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
selectionMode'none' | 'single' | 'multiple'The type of selection that is allowed in the collection.
selectionBehavior'toggle' | 'replace'Default'toggle'How multiple selection should behave in the collection.
escapeKeyBehavior'none' | 'clearSelection'Default'clearSelection'Whether pressing the escape key should clear selection in the TagGroup or not.
Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually.
onAction(key: Key) => voidHandler that is called when a user performs an action on an item. The exact user event depends on the collection's
selectionBehaviorprop and the interaction modality.shouldSelectOnPressUpbooleanWhether selection should occur on press up instead of press down.
onRemove(keys: Set<Key>) => voidHandler that is called when a user deletes a tag.
disabledKeysIterable<Key>The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
disallowEmptySelectionbooleanWhether the collection allows empty selection.
selectedKeys'all' | Iterable<Key>The currently selected keys in the collection (controlled).
defaultSelectedKeys'all' | Iterable<Key>The initial selected keys in the collection (uncontrolled).
onSelectionChange(keys: Selection) => voidHandler that is called when the selection changes.
styleCSSPropertiesThe inline style for the element.
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.renderDOMRenderFunction<'div', undefined>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
childrenReactNode | ((item: T) => ReactNode)The contents of the collection.
itemsIterable<T>Item objects in the collection.
dependenciesReadonlyArray<any>Values that should invalidate the item cache when using dynamic collections.
renderEmptyState(props: TagListRenderProps) => ReactNodeProvides content to display when there are no items in the tag list.
refRef<HTMLDivElement>
ChipGroup also takes the 70 attributes and events of the element it renders.
Chip
variantrequired'input' | 'filter' | 'assist' | 'suggestion'Four variants: assist, filter, input, and suggestion
assist: Assist chips represent smart or automated actions that can span multiple appsfilter: Filter chips represent filters for a collectioninput: Input chips represent discrete pieces of information entered by a personsuggestion: Suggestion chips help narrow a person’s intent by presenting dynamically-generated suggestions
isElevatedbooleanDefaultfalseChip elevation defaults to 0 but can be elevated if they need more visual separation
Chip containers can be elevated if placed on top of an image or dynamic background.
Props of Chip (29)
classNameClassNameOrFunction<TagRenderProps>Default'react-aria-Tag'The CSS className for the element. A function may be provided to compute the class based on component state.
idKeyA unique id for the tag.
textValuestringA string representation of the tags's contents, used for accessibility. Required if children is not a plain text string.
isDisabledbooleanWhether the tag is disabled.
onAction() => voidHandler that is called when a user performs an action on the item. The exact user event depends on the collection's
selectionBehaviorprop and the interaction modality.childrenChildrenOrFunction<T>The children of the component. A function may be provided to alter the children based on component state.
styleCSSProperties | (values: TagRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties | undefinedThe inline style for the element. A function may be provided to compute the style based on component state.
renderDOMRenderFunction<'div', TagRenderProps>Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if
<button>is expected, you cannot render an<a>). - Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
- You must render the expected element type (e.g. if
hrefHrefA URL to link to. See MDN.
hrefLangstringHints at the human language of the linked URL. SeeMDN.
targetHTMLAttributeAnchorTargetThe target window for the link. See MDN.
relstringThe relationship between the linked resource and the current page. See MDN.
downloadboolean | stringCauses the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
pingstringA space-separated list of URLs to ping when the link is followed. See MDN.
referrerPolicy'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'How much of the referrer to send when following the link. See MDN.
routerOptionsOptions for the configured client side router.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
onClick(e: MouseEvent<FocusableElement>) => voidNot recommended – use
onPressinstead.onClickis an alias foronPressprovided for compatibility with other libraries.onPressprovides additional event details for non-mouse interactions.refRef<HTMLDivElement>
Chip also takes the 69 attributes and events of the element it renders.