Example#
Usage#
Use an icon button where a glyph alone is understood by everyone: close, search, menu, play, previous and next. It has the Button's faces and travel, in a square key.
- The name is required.
labelis the accessible name and the tooltip text, so the action is never a mystery on hover or to a screen reader. - Variants.
secondary(default),primaryfor the firm choice andquietbeside other keys, such as a dialog's close key. There is no action variant: the main action always has words. - Toggles and counts.
pressedmakes a toggle key (aria-pressed);countprints aCountat the top-end corner and adds it to the name, such as "Inbox, 3 waiting". - Sizes.
sm40,md44 (default),lg52 px squares, with 18, 20 and 24 px glyphs from the shape alphabet. On touch screens no key is under 44 px and the tooltip is off; the name is still announced.
Anatomy#
- KeyA square Button face with the same rule and offset.
.mk-icon-button - GlyphOne shape from the alphabet, hidden from assistive tech.
.mk-icon-button-glyph
Volume#
Reading layer: the key prints the same at every volume, like the Button it is cut from.
Quiet
Studio
Press
Rave
Content#
- The label names the action, not the picture: "Close the menu", "Search the docs", never "X" or "Magnifier".
- Sentence case, a verb first, four words at most, because it is also the tooltip.
- Use the same glyph for the same action everywhere; a glyph never stands for two things on one site.
Do and don't#
Do
Don't
Accessibility#
labelis the accessible name and the tooltip's words, so the tooltip never holds the only copy.- The tooltip opens on hover after 400 ms and on keyboard focus, closes on Escape, and never opens from a touch.
- Squares are 40, 44 and 52 px, and at least 44 px on touch screens.
| Keys | What happens |
|---|---|
| Tab | Moves focus to the key; the tooltip opens on keyboard focus |
| Enter | Activates the key |
| Space | Activates the key; a toggle flips aria-pressed |
| Escape | Closes the tooltip and keeps focus on the key |
The colour pairs it prints, with their contrast on both papers:
| Text | Surface | Role | Bone | Night |
|---|---|---|---|---|
--mk-text | --mk-surface-raised | ui | not in this look | not in this look |
--mk-on-slab | --mk-slab | label | 16.49:1 · Lc 98.7, passes | 16.21:1 · Lc 95.1, passes |
--mk-on-selected | --mk-selected | ui | not in this look | not in this look |
--mk-text | --mk-hover | ui | not in this look | not in this look |
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
label required | string | none | Required: the accessible name, also the tooltip (a tooltip never holds the only copy, 20 §3). |
glyph required | GlyphName | none | A shape-alphabet glyph (10 §4.9), drawn at 18 / 20 / 24 px. |
tooltip | boolean | true | Wrap in `Tooltip` on fine pointers (default true). |
tooltipSide | TooltipSide | none | |
variant | IconButtonVariant | none | |
size | Size | none | |
pressed | boolean | none | |
count | number | none | |
countLabel | ((count: number) => string) | none | |
href | string | none | |
render | RenderProp | none |
Tokens#
System tokens (21)
--mk-border--mk-border-thick--mk-control-h-sm--mk-disabled--mk-dur-hover--mk-dur-key-sink--mk-dur-reduced--mk-ease-out--mk-focus--mk-hover--mk-on-selected--mk-on-slab--mk-radius-control--mk-rule--mk-selected--mk-shadow-key--mk-slab--mk-surface-raised--mk-target-touch--mk-text--mk-text-disabled
Its own properties (6)
--mk-icon-button-size--mk-key-edge--mk-key-face--mk-key-label--mk-key-offset--mk-key-rule
Changelog#
Arrived in 0.1.0.
IconButton'scountnow prints aCountat its corner. Read the whole entry- phone-frame: video in a
PhoneFramestarts paused with a play and pause key at the frame's bottom end (the client leafPhoneVideo, on IconButton's markup, named "Play {label}" and "Pause {label}"), instead of the platform's controls (DF-33, supersedes D-N78). Read the whole entry
- The reading layer's controls, overlays, forms and visitor prefs (P2-T1 to P2-T5): every Button is the comic hit key, with IconButton, Link and Tooltip; Input, Textarea, Select, Checkbox and CheckboxGroup, Radio and RadioGroup, Switch, Slider with the ruler, RulerReadout and SegmentedControl; Dialog, Drawer, NavSheet, Tabs, Disclosure, Faq and faqJsonLd on Base UI 1.9 where the platform falls short; Field, Fieldset, Form with the site's inline validation, ErrorSummary, Callout, Honeypot, FormTimestamp and QuoteForm; PrefsScript under 1 KB, usePref and setPref with cross-tab sync, ThemeToggle and the visitor VolumeDial; VisuallyHidden.