Reference

IconButton

Icon-only button. label is its accessible name, never visible text.

IconButton(icon: String, label: String, size: Enum, …) { … }

Before 5.0

icon

label

size

tone

type

button

submit

reset

disabled

0 stars

Example

wf

state stars = 0 Row(gap: .sm, align: .center) { IconButton(icon: "star", label: "Star this project").primary { on click { stars = stars + 1 } } IconButton(icon: "edit", label: "Edit") IconButton(icon: "copy", label: "Copy link") IconButton(icon: "trash", label: "Delete").danger Text("{stars} stars").muted }

Sizes

wf

Row(gap: .sm, align: .center) { IconButton(icon: "close", label: "Close").sm IconButton(icon: "close", label: "Close") IconButton(icon: "close", label: "Close").lg }

Saying what it opens

wf

state open = false IconButton(icon: "menu", label: "Actions", aria-haspopup: "menu", aria-expanded: open) { on click { open = !open } }

Disabled

wf

IconButton(icon: "download", label: "Download", disabled: true)

Props

Props of IconButton
PropTypeUnsetMeaning

icon:

String

The icon it shows, one of the built-in icon names; a value that reads state follows it

label:

String

none

Its accessible name (aria-label) and tooltip (title, unless one is written), never visible text; without it the tooltip is the icon's name and it has no name (A02)

size:

one of its cases

md

Its square size. Written as a flag, .sm, or by name, size: .sm.

  • .sm: 28px
  • .md (the default): 36px, the default
  • .lg: 48px

tone:

one of its cases

none: the text colour

The icon's colour; the button stays transparent. Written as a flag, .primary, or by name, tone: .primary.

  • .primary: The brand colour
  • .danger: Red: destructive

type:

one of its cases

button

What it does inside a form; any button not .submit or .reset never submits one. Written as a flag, .button, or by name, type: .button.

  • .button (the default): A plain button
  • .submit: Submits the enclosing form
  • .reset: Resets the enclosing form

disabled:

Bool

false

Whether it is inert: it cannot be pressed or focused. Written as a flag, .disabled, or disabled: true.

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.sm

.md

.lg

.primary

.danger

.button

.submit

.reset

.disabled

Events

The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.

DOM events IconButton answers
EventSendsMeaning
on clickDOMThe element was clicked or activated

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Renders with the class wf-icon-btn, stable across releases, so a stylesheet may target it.