Skip to content

Icon Button

The icon-only preset of Button: iconOnly makes it square and sizes the glyph; all variants apply. It is the same component — a dismiss “×” is just iconOnly + a glyph + an ariaLabel.

<script>
import Button from "@invisible-ui/svelte/Button.svelte";
import Icon from "@invisible-ui/svelte/Icon.svelte";
</script>
PropTypeDefaultDescription
actionAction<HTMLElement>() => {}Optional extra Svelte action applied to the underlying <button>. Overlay components (Dialog, Popover, …) pass their triggerAction here to compose the Button as their trigger.
variantButtonVariant"default"
disabledbooleanfalse
loadingbooleanfalseLoading state: shows an inline spinner in place of the leading icon (or of the glyph, for icon-only buttons), announces aria-busy and ignores presses. The label stays visible and the button stays focusable.
loadingStatusstring | undefinedundefinedLive loading message announced on every change while loading — for a succession of backend-reported steps ("Uploading…" → "Processing…"). It is visually hidden (the button label stays stable); assistive tech hears each step through the spinner's polite status region.
type"button" | "submit" | "reset""button"
onpress((event: Event) => void) | undefinedundefinedCalled when activated (click, or Enter/Space).
copystring | undefinedundefinedText to copy to the clipboard when the button is pressed. After a successful copy, a confirmation shows beside the button for two seconds and is announced politely (ADR 0016).
copiedLabelstring | undefinedundefinedThe confirmation shown after a copy. Defaults to the i18n catalog's "Copied".
leftIconboolean | undefinedundefinedShow a leading icon. Defaults on for danger.
rightIconbooleanfalseShow a trailing icon.
iconOnlybooleanfalseSquare, icon-only button (pass one icon as children + an ariaLabel). The CloseButton is a preset of this.
ariaLabelstring | undefinedundefinedAccessible name; required for icon-only buttons.
leftSnippet | undefinedundefinedReplaces the built-in leading icon.
rightSnippet | undefinedundefinedReplaces the built-in trailing icon.
  • ariaLabel is mandatory: with no visible text, the accessible name must come from somewhere — the demo’s “Close”, “Add”, “Delete” are what screen readers announce.
  • The hit area keeps the WCAG minimum target size via --ds-components-button-icon-min-size.
<Button iconOnly variant="ghost" ariaLabel="Close" onpress={() => dismiss()}>
<Icon><line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" /></Icon>
</Button>

Themeable via --ds-components-button-icon-min-size, --ds-components-button-icon-size, --ds-components-button-spacing-icon (plus the shared --ds-components-button-*).

A count or a status dot can sit on the button’s corner. In Elements, add a <ds-count slot="badge">: it renders beside the button, not inside it, so the button keeps its own name and the count describes it.

<ds-button icon-only variant="ghost" aria-label="Notifications">
<svg viewBox="0 0 24 24" aria-hidden="true">…</svg>
<ds-count slot="badge" count="3" label="3 unread notifications"></ds-count>
</ds-button>