apps/mantine.dev/src/pages/core/chip.mdx
import { ChipDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.Chip);
import { useState } from 'react';
import { Chip } from '@mantine/core';
function Demo() {
const [checked, setChecked] = useState(false);
return (
<Chip checked={checked} onChange={() => setChecked((v) => !v)}>
My chip
</Chip>
);
}
To use Chip with Tooltip and other similar components, set refProp="rootRef"
on the Tooltip component:
The Chip.Group component manages the state of child Chip components.
Set the multiple prop to allow multiple chips to be selected at a time:
import { useState } from 'react';
import { Chip } from '@mantine/core';
function Single() {
// string value when multiple is false (default)
const [value, setValue] = useState('react');
return (
<Chip.Group multiple={false} value={value} onChange={setValue}>
<Chip value="react">React</Chip>
<Chip value="ng">Angular</Chip>
<Chip value="svelte">Svelte</Chip>
<Chip value="vue">Vue</Chip>
</Chip.Group>
);
}
function Multiple() {
// array of strings value when multiple is true
const [value, setValue] = useState(['react']);
return (
<Chip.Group multiple value={value} onChange={setValue}>
<Chip value="react">React</Chip>
<Chip value="ng">Angular</Chip>
<Chip value="svelte">Svelte</Chip>
<Chip value="vue">Vue</Chip>
</Chip.Group>
);
}
Chip and Chip.Group components are accessible by default – they are built with native radio/checkbox inputs,
all keyboard events work the same as with native controls.