Button
The basic button component, and also the button base for ToggleButton, PopupButton, ButtonMenuSelectWidget and other components.
Basic usage
Icons and indicators
icon takes an icon name (see Icon), indicator takes one of the four indicators (see Indicator). They render on opposite ends of the label.
When the label is icon-only, turn on invisibleLabel: the label is visually hidden but kept as the accessible name, and title falls back to the label text when not given explicitly.
Flags and variants
flags affect color and icon tinting, framed={false} switches to the unframed form, and active marks a selected/activated state.
A framed button inverts as a whole when primary, active, or disabled, and the icon and indicator invert with it; otherwise it is tinted by the color flag in flags. The available color flags are progressive, destructive, invert, error, warning and success.
As a link
Given href, the inner <a> becomes a navigable link and target chooses where it opens. rel defaults to nofollow; when using target="_blank" you should add noopener yourself.
This component does not sanitize href (it bypasses the original OO.ui.isSafeUrl), and React does not block dangerous schemes such as javascript: at runtime either. Links of untrusted origin (e.g. concatenated from user input) must have their protocol validated by you first, otherwise this is an XSS; when you want component-level sanitizing, use the exported sanitizeUrl.
Disabled
disabled outputs oo-ui-widget-disabled and aria-disabled (not the native disabled); the button then ignores clicks, its tabindex becomes -1, and href no longer takes effect. Inside a ButtonGroup, the group-level disabled state propagates to the buttons in it.
Focus and keyboard
- The focusable element is the inner
<a>; the root<span>is not focusable. To focus the button manually, useanchorRef(the componentrefpoints to the outer<span>). - Enter / Space trigger
onClick;onKeyPressprevents Space from scrolling the page whenever a click handler is present. - The pressed state (
oo-ui-buttonElement-pressed) is maintained by the component in JS: CSS has no keyboard-press pseudo-class, so keyboard press and release are handled by explicit event listeners. Thepressedprop is OR-ed with it, for cases like "keep the button pressed while its associated menu is open". titleandaccessKeyland on the inner<a>; whentitleis not given and the label is hidden it falls back to the label text, and whenaccessKeyis present a key hint is appended totitle(the chord text can be localized via OOUIProvider).
API
ButtonFlag is 'progressive' | 'destructive' | 'invert' | 'error' | 'warning' | 'success' | 'primary' | 'safe' | 'back' | 'close'; the first six decide tinting, the last four are button-specific form flags.