Whakerexa > Components > Forms

Button

Load button.css to access four ready-to-use button patterns. Each can be customized through CSS variables. No JavaScript required.

Default button - no class applied

<button>a button</button>
<button disabled>a disabled button</button>

Variables

Colors are controlled by the theme variables:

Variable Role
--buttons-bg-color Background (resting state)
--buttons-bg-color-hover Background on hover / focus
--buttons-fg-color Label color

An element that carries role="button"

role="button" is drawn the way a <button> is, on whatever element carries it. A command that no longer answers says it with aria-disabled="true": it keeps the look it has and is no longer lit under the pointer, the way a <button disabled> is not.

a div
a span a span that does not answer
<div role="button" tabindex="0">a div</div>
<span role="button" tabindex="0">a span</span>
<span role="button" tabindex="0" aria-disabled="true">a span that does not answer</span>
<button disabled>a disabled button</button>

Text-reveal

.text-reveal-button shows only an icon at rest. On hover or keyboard focus, the text label appears beside it and the button expands to fit.

Accessibility. The native <button> element is keyboard-focusable (Tab) and activatable with Enter or Space — no JavaScript required. The SVG icon must carry aria-hidden="true" since it is decorative. The <span> label then provides the button's accessible name, read by screen readers. The :focus state triggers the same visual expansion as hover, giving keyboard users the same feedback as pointer users.

<button class="text-reveal-button" data-icon="download">
    <span>Label</span>
</button>

Size is controlled by --text-reveal-height and --text-reveal-width (both default to calc(var(--font-size) * 1.6)).

<button class="text-reveal-button" data-icon="download"
        style="--text-reveal-height: calc(var(--font-size) * 3);
               --text-reveal-width:  calc(var(--font-size) * 3);">
    <span>Label</span>
</button>

A drawing of your own is written inside the button, and needs no data-icon: the component dresses what it holds, whether the drawing comes from a set or from the page itself.

<button class="text-reveal-button">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none"
         stroke="currentColor" stroke-width="2" stroke-linecap="round"
         stroke-linejoin="round" width="100%" height="100%" aria-hidden="true">
        <polygon points="18 3 8 18 15 18 14 29 24 14 17 14 18 3" />
    </svg>
    <span>Boost</span>
</button>

The reach of an action

Three buttons say, before they are clicked, how far their action goes: .danger-button for what cannot be undone — deleting, revoking, emptying — .warning-button for what engages without destroying, and .success-button for what validates or adds. Each is drawn at rest and filled under the pointer, so the reach is said twice: by the color, and by the ground that changes. Keep them for those actions, or they stop being read.

<button class="danger-button">Delete the file</button>
<button class="warning-button">Replace the file</button>
<button class="success-button">Install</button>

Busy

aria-busy="true" on a button says the work it started is not finished: a ring is drawn at the end of the label and the pointer becomes the one of a wait. The button keeps its place and the size of its text. A screen reader reads the attribute, so the state is not told by the drawing alone. In contrast mode the ring stands still, as every other movement of the framework does.

The attribute is written and removed by the page: the framework draws the state, it does not decide when it begins or ends. A command that must not answer twice also carries disabled, which the framework already dresses.

<button aria-busy="true">Sending</button>

Icon only

.icon-button is a square the size of a command, holding a drawing and nothing else. Its name is written in aria-label: it is read by whoever does not see the drawing, and it does not wait for a pointer that a touch screen has not got — which is what separates it from .text-reveal-button, whose label is revealed. The drawing takes the room the button decided, whether it is written in the page or put there by an icon set.

<button class="icon-button" aria-label="Add">
    <svg ... aria-hidden="true">...</svg>
</button>

--icon-button-size says the side of the square, and the drawing takes six tenths of it. A page that wants another size writes the variable on the button, or on what holds a set of them.

Row of buttons

A row of buttons is a .wrap-panel of layout.css: the distance between them is said once by --wrap-panel-gap, and a row wider than the room it is given wraps, each button keeping the width of its label. No class is needed on the buttons themselves.

<div class="wrap-panel">
    <button>Open</button>
    <button>Apply</button>
</div>

Toggle

A toggle is a button that stays pressed: a tool left on, a panel left open. aria-pressed carries its state — true when it is on, false when it is off — and a screen reader reads it. The ground takes the shade of a hovered command and a line is drawn inside, so the state is told by more than the color, and the one that is on is seen at rest.

A button with no aria-pressed is not a toggle, and the attribute is written and changed by the page. Several toggles that exclude one another are a .toggle-group, below.

<button aria-pressed="true">Bold</button>
<button aria-pressed="false">Italic</button>

Toggle group

Load togglegroup.css and add .toggle-group to a container of .menuitem labels to render a segmented control for mutually-exclusive choices — the inner borders flatten and overlap so the group reads as one connected control instead of separate pills.

Accessibility. The container carries role="radiogroup" and an aria-label. Each option is a real <input type="radio"> wrapped in its <label> — arrow-key cycling and checked/unchecked announcement come from the native radio semantics, not from JavaScript. The input is visually hidden (not aria-hidden: it stays focusable and meaningful to assistive tech) while the label supplies both the visible control and its accessible name.

<section class="toggle-group" role="radiogroup" aria-label="Text alignment">
    <label class="menuitem" for="align-left">
        <input type="radio" name="align" id="align-left" checked> Left
    </label>
    <label class="menuitem" for="align-center">
        <input type="radio" name="align" id="align-center"> Center
    </label>
    <label class="menuitem" for="align-right">
        <input type="radio" name="align" id="align-right"> Right
    </label>
</section>

The checked item swaps to --buttons-bg-color-hover / --buttons-fg-color; corner rounding uses --border-radius on the first and last items only.