Chip
A composable, accessible Chip component for modern React applications.
tsx
import { Chip } from '@nofinite/nui';Interactive Preview
Loading preview...
A compact pill-shaped component used to represent selections, filters, or small entities. Supports selection state, removability, icons, sizes, and keyboard-accessible interaction.
Usage
Basic Chip
tsx
import { Chip } from '@nofinite/nui';
<Chip>React</Chip>
<Chip size="sm">Small chip</Chip>Selectable Chip
tsx
<Chip selected onSelect={() => console.log('Selected')}>
Selected Chip
</Chip>Removable Chip
tsx
<Chip removable onRemove={() => console.log('Removed')}>
Removable
</Chip>Chip with Icons
tsx
<Chip iconLeft={<Icon />} iconRight={<Icon />}>
Messages
</Chip>Interactive Chip
tsx
<Chip onSelect={() => console.log('Clicked')}>Clickable Chip</Chip>Variants
Chip supports interaction-based variants.
tsx
<Chip /> // Default chip
<Chip selected /> // Selected chip
<Chip onSelect={() => {}} /> // Interactive chip
<Chip removable /> // Removable chipAvailable variants:
default– Static chipselected– Active chip with highlighted backgroundinteractive– Chip that responds to click and keyboard interactionremovable– Chip with remove action
Guidelines:
- Use
selectedfor filter or tag selection states. - Use
interactivewhen chip triggers an action. - Use
removablefor dynamic lists like tags or recipients.
Sizes
| Size | Height | Font Size | Notes |
|---|---|---|---|
sm | 24px | 12px | Compact chips for dense UI |
md | 32px | 14px | Default size |
States
| State | Description |
|---|---|
default | Neutral chip appearance |
selected | Highlighted active state |
interactive | Hover + active feedback |
removable | Displays remove control |
Accessibility
- Interactive chips receive
role="button" - Keyboard interaction via Enter and Space
aria-pressedreflects selected state- Remove button is separately focusable and accessible
- Focus-visible ring improves keyboard navigation
Best Practices
Do
- Use chips for filters, tags, or selected items
- Provide remove action for user-generated tags
- Use selected state to show active filters
- Keep chip text short
Don’t
- Use chips for primary navigation
- Overload chips with long content
- Hide remove actions behind complex gestures
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
removable | boolean | false | If true, renders a trailing 'X' button that triggers onRemove |
selected | boolean | false | Controls the visual and ARIA active state of the chip |
iconLeft | ReactNode | — | — |
iconRight | ReactNode | — | — |
size | enum | md | — |
onRemove | (() => void) | — | Callback fired when the 'X' button is clicked |
onSelect | (() => void) | — | Callback fired when the main body of the chip is clicked or activated via keyboard |