Primitives
IconButton
An action shown only as an icon, for toolbars, cards and dense rows
Markdown version for agents · 5 stories in Storybook(opens in a new tab)
import { IconButton } from '@amezquita/design-system/components/primitives/IconButton'Live render
Props
| Prop | Type | Description |
|---|---|---|
icon | React.ReactNode | The icon. It's hidden from screen readers; label names the action. |
label | string | The action's name, e.g. "Close" or "Search". Required: it is the only name a screen reader gets. |
variant? | 'primary' | 'secondary' | 'ghost' | Emphasis, as on Button. Defaults to ghost, the usual weight for a toolbar or card action. |
size? | 'md' | 'sm' | md (default) is a 44px square. sm draws a smaller square for dense rows; its hit area still reaches 44px. |
onClick? | (event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void | |
disabled? | boolean | |
loading? | boolean | Shows a spinner in place of the icon and blocks the action, as on Button. |
type? | 'button' | 'submit' | 'reset' | |
href? | string | Renders an <a>, for an action that navigates. |
Also accepts all props of: Omit<React.HTMLAttributes<HTMLElement>, 'onClick' | 'type' | 'children' | 'aria-label'>
Best practices
Do
- Use an icon people already know for the action: a cross to close, a magnifier to search, a bin to delete.
- Write the
labelas the action ("Delete row"), not the icon ("Bin"). - Add a Tooltip showing the label when the icon alone may not be clear.
- Use
ghostfor repeated actions in a list, so the row isn't a wall of filled circles.
Don't
- Don't use an IconButton for the main action of a view; give that a Button with a visible label.
- Don't put two different actions behind the same icon on one screen.
- Don't use
smwhere people tap a lot on touch screens; the square looks small even though the target isn't.
Accessibility
- Semantic element:
<button>, or<a>withhref(Button's rules) - The
labelis the only accessible name, so it's required; the icon isaria-hidden - Hit area is 44×44px at both sizes;
smextends it past the visible square - Keyboard:
EnterandSpace, as Button