Chip
An unstyled chip component with compound composition for representing entities.
Build fully custom chip elements with complete control over layout and styling.
Pre-styled Versions
Features#
- Compound component API with five sub-components:
Root,Start,Label,End,Remove - Built-in visibility state — chip hides itself when removed
onRemovecallback for reacting to dismissal eventsRemovesub-component with keyboard support (Enter, Backspace)
Usage#
import { Chip } from 'primereact/chip';<Chip.Root>
<Chip.Start />
<Chip.Label />
<Chip.End>
<Chip.Remove />
</Chip.End>
</Chip.Root>Behavior#
Polymorphic Rendering#
Use as on any sub-component to change the rendered HTML element.
<Chip.Root as="span">
<Chip.Label as="span">Tag</Chip.Label>
</Chip.Root>Default elements: Root=div, Start=div, Label=div, End=div, Remove=span.
Render Function Children#
Sub-components accept a render function as children, providing access to the component instance.
<Chip.Label>{(instance) => <span>{instance.chip?.state.visible ? 'Visible' : 'Hidden'}</span>}</Chip.Label>Pass Through#
Some parts may not be visible in the preview depending on the component's current state.
/* Select a part to see its CSS selector for custom styling */API#
ChipRoot#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ChipRootInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ChipRootInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ChipRootInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ChipRootPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ChipRootInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
variant | "text" | "outlined" | — |
| Defines the content type. | ||
onRemove | (event: ChipRootRemoveEvent) => void | — |
| Callback fired when the chip is removed. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | chip |
data-part | root |
Defines passthrough(pt) options of Chip component.
| label | type | description |
|---|---|---|
| root | ChipRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
| label | ChipRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the label's DOM element. |
| remove | ChipRootPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the remove's DOM element. |
| start | ChipRootPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the start's DOM element. |
| end | ChipRootPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the end's DOM element. |
ChipStart#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ChipStartInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ChipStartInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ChipStartInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ChipStartPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ChipStartInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ChipStart component.
| label | type | description |
|---|---|---|
| root | ChipStartPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the root's DOM element. |
ChipLabel#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ChipLabelInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ChipLabelInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ChipLabelInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ChipLabelPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ChipLabelInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ChipLabel component.
| label | type | description |
|---|---|---|
| root | ChipLabelPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
ChipEnd#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ChipEndInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ChipEndInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ChipEndInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ChipEndPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ChipEndInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ChipEnd component.
| label | type | description |
|---|---|---|
| root | ChipEndPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the root's DOM element. |
ChipRemove#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: ChipRemoveInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: ChipRemoveInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | ChipRemoveInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<ChipRemovePassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: ChipRemoveInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
Defines passthrough(pt) options of ChipRemove component.
| label | type | description |
|---|---|---|
| root | ChipRemovePassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the root's DOM element. |
Accessibility#
Screen Reader#
Chip uses its label content as the default accessible name. Provide aria-label or aria-labelledby on Chip.Root to override. Removable chips have a focusable remove element with tabIndex="0".
Keyboard Support#
| Key | Function |
|---|---|
enter | Hides removable chip |
backspace | Hides removable chip |