@akhatmirzo/ui

IconButton

An icon-only square button with a required aria-label and 3 sizes.

Import

import { IconButton } from '@akhatmirzo/ui';

When to use

  • When space is tight and the icon is universally understood — close (✕), edit, delete, toolbar actions. If the meaning isn't obvious, use a Button with text.
  • aria-label is required. TypeScript won't compile without it. Screen readers can't see the icon and read only this label, so phrase it as an action: "Close", "Edit".
  • Need a visible hint? Wrap the button in a Tooltip.
  • In toolbars and table rows, the ghost variant keeps things light.

Variants

The same variants as Button, minus link: primary, soft (default), outline, ghost and danger. See the Button page for when to use each.

Sizes

Square: 32, 40 and 48px — the same heights as Button and Input. The icon scales automatically to 16 / 18 / 20px. The sm size has an invisible 40px hit area.

States

While loading, a spinner replaces the icon, the button keeps focus and clicks are ignored. Try clicking the first button.

Customization

Change shape and layout with className — for example, rounded-full for a floating action button. The example below builds a toolbar from ghost buttons.

IconButton accepts asChild too: you get the button styles on your own <a> (or Next.js <Link>).

Props

IconButton is a thin wrapper around Button. It accepts loading, disabled, asChild, labels and every other <button> attribute; leftIcon, rightIcon and fullWidth are not available here.

PropTypeDefaultDescription
aria-labelrequiredstring—The name screen readers announce
variant'primary' | 'soft' | 'outline' | 'ghost' | 'danger''soft'Look and visual weight
size'sm' | 'md' | 'lg''md'Square size: 32 / 40 / 48px
loadingbooleanfalseShows a spinner instead of the icon, blocks clicks, sets aria-busy
disabledbooleanfalseDisables the button
asChildbooleanfalseRenders its child instead of its own element (e.g. <a>)
labels{ loading?: string }{ loading: 'Yuklanmoqda' }Loading text for screen readers
childrenReactNode—The icon (SVG). Don't put text here — that's what Button is for

Data attributes are the same as Button's: data-variant, data-size, data-disabled and data-loading.

Accessibility

  • A name is required. aria-label is enforced by the type — an unnamed button won't compile.
  • Native <button type="button"> — activates with Enter and Space and never submits a form by accident.
  • The icon is hidden from screen readers (aria-hidden); the only thing announced is the aria-label.
  • Loading. Sets aria-busy="true", and a hidden aria-live region announces the labels.loading text.
  • Small size. size="sm" looks 32px but has a 40px hit area.

On this page