Icon button
npx shadcn add @klarhimmel/icon-buttonCopy for AIExamples
Variants
Toolbar
Toggle
DetailsAbout, usage, props and more
A button with only an icon. The label is its accessible name and its tooltip, so it can never be unnamed.
When to use
Use for
Toolbars, table rows and tight corners: close, share, bold.
Not for
Anything a word would explain better. Use Button.
Pairs with
Tooltip (built in), Menu triggers, toolbars.
Preview
Ghost, soft, secondary, primary and disabled. Hover or tab to a button for its name.
Import
Import
- Files
- icon-button.tsx, in components/klarhimmel/ui/. With it: editing, theme, tooltip, utils.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- Limit
- Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | required | Required: the accessible name, also shown as the tooltip. |
shortcut | string | - | A shortcut shown next to the label in the tooltip. |
size | 'sm' | 'md' | 'lg' | 'md' | The small size is 36 px with a 44 px hit area. |
variant | 'ghost' | 'soft' | 'secondary' | 'primary' | 'ghost' | Visual style. |
active | boolean | - | A toggle button: sets aria-pressed and the pressed look. |
children | ReactNode | required | |
noTooltip | boolean | - | Skip the tooltip when the label is already visible nearby. |
tooltipSide | 'top' | 'right' | 'bottom' | 'left' | - | Where the tooltip opens and the hover delay in ms. |
tooltipDelay | number | - | Where the tooltip opens and the hover delay in ms. |
native attributes | ButtonHTMLAttributes | - | Every native attribute of the element passes through, className included. |
Accessibility
| Key | Does |
|---|---|
Enter / Space | Activates the button |
Tab | Moves focus; the tooltip shows with it |
Escape | Hides the tooltip |
The label is required: it is the only name a screen reader hears.
Accessibility