Fragiola

API: components

Button

An element that performs an action, native or rendered as another element, that can stay focusable while disabled (the APG button), in each framework.

An element the user activates to perform an action (WAI-ARIA APG button pattern): a native <button>, or another element (render) that behaves as one, with the keys a native button has. A disabled Button can stay focusable (focusableWhenDisabled), for a button that is busy for a moment and must not lose the focus. A toggle button and a menu button are not Button's: the menu button is Menu's Trigger.

Publish a post
Gallery

Behaviour

  • Native: a <button>, type="button" unless you give a type (a type="submit" Button submits its form).
  • Not native (nativeButton false, with render giving a span or a div): the Button adds role="button", tabindex="0", and the keys of a native button: Enter clicks on key down, Space clicks on key up, and Space's key down does not scroll the page.
  • Disabled: a press, a pointer down and every key but Tab are ignored, and your click, pointer down and key handlers do not run. A native one is disabled, a non-native one aria-disabled="true" and out of the tab order.
  • Focusable when disabled: with focusableWhenDisabled, a disabled Button stays in the tab order and focusable (aria-disabled="true" instead of disabled), and still ignores presses and every key but Tab: a focusable disabled submit button does not submit on Enter.

Anatomy

partelementdata-primitives-partrole
Buttonbuttonbutton-rootthe button; or your element (render), with role="button"

Usage

import { Button } from "@fragiola/primitives-react/button";

<Button disabled={busy} focusableWhenDisabled onClick={publish}>
    Publish
</Button>
<Button nativeButton={false} render={<span />} onClick={archive}>
    Archive
</Button>;

Props

It also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Vue binds them as props (focusable-when-disabled, :native-button); Angular as inputs ([focusableWhenDisabled], [nativeButton]). Vue and Angular take the click, pointer and key listeners as native events (@click, (click)).

Button

proptypedefaultdescription
disabledbooleanfalseignores presses and keys
focusableWhenDisabledbooleanfalsea disabled Button stays in the tab order and focusable
nativeButtonbooleantruewhether the rendered element is a native <button>; false with a render that gives another element
type"button" | "submit" | "reset""button" (native)forwarded
tabIndex (react)numbera non-native Button's tab index while it is focusable (0 without it)
onClick (react)MouseEventHandlera click; not while disabled
onMouseDown (react)MouseEventHandlernot while disabled
onPointerDown (react)PointerEventHandlernot while disabled (its default is prevented)
onKeyDown (react)KeyboardEventHandlerruns before the non-native keys; preventing its default keeps them from clicking; not while disabled
onKeyUp (react)KeyboardEventHandlerruns before Space's click on a non-native Button; not while disabled

State and part attributes

caseattributes
nativetype="button" (unless given), data-disabled while disabled; disabled: disabled; disabled and focusableWhenDisabled: aria-disabled="true" instead of disabled
not nativerole="button", tabindex="0", data-disabled while disabled; disabled: aria-disabled="true" and tabindex="-1"; disabled and focusableWhenDisabled: aria-disabled="true" and tabindex="0"

Its accessible name is its content, or your aria-label.

Keyboard

keyaction
Enteractivates (a click); a non-native Button clicks on key down
Spaceactivates (a click); a non-native Button clicks on key up, and its key down does not scroll
Tabmoves on; a disabled Button is skipped, unless focusableWhenDisabled

While disabled, every key but Tab does nothing.

Exports

entryexports
@fragiola/primitives-react/buttonButton, ButtonProps, ButtonState, RenderProp
@fragiola/primitives-vue/buttonButton, ButtonProps, ButtonState, RenderSlotProps
@fragiola/primitives-angular/buttonButton, ButtonState, ButtonType