Skip to content

IconButton ​

A button with an icon and no word. Its label is both the accessible name and the tooltip.

tsx
import { IconButton } from '@adecore/ui';
tsx
import { ButtonGroup, IconButton, Separator, shortcut } from '@adecore/ui';
import { Bold, ChevronRight, Italic, RefreshCw, Settings, Trash } from 'lucide-react';
import { useState } from 'react';

const REFRESH = shortcut('Mod+R');

export default function IconButtonDemo() {
    const [bold, setBold] = useState(true);
    const [italic, setItalic] = useState(false);
    const [refreshing, setRefreshing] = useState(false);
    const [open, setOpen] = useState(false);

    const refresh = (): void => {
        setRefreshing(true);
        window.setTimeout(() => setRefreshing(false), 1200);
    };

    return (
        <div className="flex items-center gap-2">
            <ButtonGroup>
                <IconButton icon={Bold} label="Bold" aria-pressed={bold} onClick={() => setBold(!bold)} />
                <IconButton icon={Italic} label="Italic" aria-pressed={italic} onClick={() => setItalic(!italic)} />
            </ButtonGroup>
            <Separator />
            <IconButton icon={RefreshCw} label="Refresh" kbd={REFRESH} busy={refreshing} onClick={refresh} />
            <IconButton
                icon={ChevronRight}
                label={open ? 'Collapse' : 'Expand'}
                aria-expanded={open}
                iconClassName={open ? 'rotate-90 transition-transform' : 'transition-transform'}
                onClick={() => setOpen(!open)}
            />
            <IconButton icon={Settings} label="Settings" tooltipSide="bottom" />
            <IconButton icon={Trash} label="Delete" tooltip="Nothing is selected" aria-disabled />
        </div>
    );
}

Sizes ​

The size sets the square, radius and icon: a 16 pixel icon in the default 32 pixel square, 14 in 28 (sm), and 12 in 24 (xs) and 20 (2xs). Never set a height, width or radius. To widen it for a word passed as children, use w-auto.

tsx
import { IconButton } from '@adecore/ui';
import { Plus } from 'lucide-react';

export default function IconButtonSizes() {
    return (
        <div className="flex items-center gap-3">
            <IconButton icon={Plus} label="Add (32, icon 16)" />
            <IconButton icon={Plus} label="Add (28, icon 14)" size="sm" />
            <IconButton icon={Plus} label="Add (24, icon 12)" size="xs" />
            <IconButton icon={Plus} label="Add (20, icon 12)" size="2xs" />
            <IconButton icon={Plus} label="Add a file" className="w-auto gap-1.5 px-2 text-xs">
                Add
            </IconButton>
        </div>
    );
}

State ​

active draws a pressed key, for a toggle that is on. For a real toggle, set aria-pressed instead; both look the same. busy replaces the icon with a Spinner.

iconClassName goes to the icon or spinner: a rotating chevron, a status tone, fill-current. For an icon of another size, pass it as children without icon.

disabled blocks the pointer, so the tooltip never opens. aria-disabled looks the same but keeps focus and the tooltip, which can say why. It does not stop onClick.

As another element ​

render merges the button into another element, such as a menu trigger:

tsx
<Menu.Root>
    <IconButton icon={Ellipsis} label="More" render={<Menu.Trigger />} />
    <Menu.Popup>...</Menu.Popup>
</Menu.Root>

Props ​

IconButton takes every prop of a <button>, plus:

PropTypeDefault
labelstringRequired. The accessible name, and the tooltip unless tooltip says otherwise.
iconLucideIcon
tooltipReactNode | falselabelA tooltip that says more than the name, or false for none.
kbdShortcut | stringPrinted in the tooltip. A Shortcut also shows under the button while the modifier is held (ShortcutHints).
tooltipSideTooltipSide'top'
sizeIconButtonSize'md''md' | 'sm' | 'xs' | '2xs'
activebooleanfalseDraws a pressed key.
busybooleanfalseA Spinner in place of the icon.
iconClassNamestringClasses for the icon.
childrenReactNodeDrawn after the icon: a count, or a word with w-auto.
renderRenderProp<button type="button" />Another element to be the button.

IconButtonProps and IconButtonSize are exported types.

Licenses and third-party notices are listed in each package.