Functional Weave
Code in TypeScript

react.form.button

A form button in primary, secondary or warning style that stays focusable while loading (GOV.UK button).

React ^19 · TypeScript only A React component: use it from a TypeScript project with React installed. A client component ("use client").

1.0.1 · published 2026-10-03 by charlie · Anterra

Pinned by 13 tests, run in TypeScript.

What it does

The GOV.UK Design System button as a React component: a `<button>` that submits its form unless told otherwise, in three styles, with a loading state that stops a double submission without taking the button away from keyboard and screen reader users.

"use client";
import { Button } from "#fune/react.form.button@^1";

<Button>Save and continue</Button>
<Button variant="secondary" type="button" onClick={findAddress}>Find address</Button>
<Button variant="warning" name="action" value="delete">Delete account</Button>
<Button loading={saving} loadingText="Saving">Save and continue</Button>

For example

  1. a primary submit button, GOV.UK's default

    <Button id="save">Save and continue</Button>

    renders

    <button class="fune-button" id="save" type="submit">Save and continue</button>
  2. no id given, none rendered

    <Button>Continue</Button>

    renders

    <button class="fune-button" type="submit">Continue</button>

The function

Written for React ^19, in TypeScript only. A component: it takes its props and renders HTML, which the tests below pin exactly.

export function Button(props: ButtonProps): JSX.Element

Its props, ButtonProps. A ? marks one the caller may leave out.

childrenReactNodethe text, in sentence case, saying what the button does
variant?ButtonVariantprimary when left out; secondary for other actions; warning (red) for a destructive one
type?ButtonTypesubmit when left out
id?stringthe button's id; none is rendered when left out
name?stringsubmitted with value when this button submits the form
value?stringsubmitted under name
disabled?booleancannot be pressed or focused; GOV.UK advises against it
loading?booleanan action is under way: still focusable, but aria-disabled and presses are ignored
loadingText?ReactNodeshown instead of children while loading, such as "Saving"
onClick?() => voidcalled when pressed, unless disabled or loading
className?stringadded to the button's classes
rendersJSX.Element

The types it declares, generated into your project

export type ButtonVariant = "primary" | "secondary" | "warning";

export type ButtonType = "submit" | "button" | "reset";

/** An action a person takes, such as "Save and continue". */
export interface ButtonProps {
  /** the text, in sentence case, saying what the button does */
  readonly children: ReactNode;
  /** primary when left out; secondary for other actions; warning (red) for a destructive one */
  readonly variant?: ButtonVariant;
  /** submit when left out */
  readonly type?: ButtonType;
  /** the button's id; none is rendered when left out */
  readonly id?: string;
  /** submitted with value when this button submits the form */
  readonly name?: string;
  /** submitted under name */
  readonly value?: string;
  /** cannot be pressed or focused; GOV.UK advises against it */
  readonly disabled?: boolean;
  /** an action is under way: still focusable, but aria-disabled and presses are ignored */
  readonly loading?: boolean;
  /** shown instead of children while loading, such as "Saving" */
  readonly loadingText?: ReactNode;
  /** called when pressed, unless disabled or loading */
  readonly onClick?: () => void;
  /** added to the button's classes */
  readonly className?: string;
}

Your code names it in one line, in the file that uses it

import { Button } from "#fune/react.form.button@^1";
impl/typescript.tsx · 49 lines · open · raw
"use client";

import type { JSX, MouseEvent, ReactNode } from "react";
import type { ButtonProps } from "./react_form_button_types.ts";

function present(node: ReactNode): boolean {
  return node !== null && node !== undefined && node !== false && node !== "";
}

/**
 * The GOV.UK button. While loading it stays enabled, so it keeps focus and a
 * screen reader still finds it, but it says aria-disabled="true" and a press
 * is swallowed, form submission included: the second click of a double click
 * sends nothing twice. disabled is the real attribute, with aria-disabled as
 * GOV.UK renders it.
 */
export function Button(props: ButtonProps): JSX.Element {
  const { children, id, name, value, disabled, loading, loadingText, onClick, className } = props;
  const variant = props.variant ?? "primary";
  const classes = [
    "fune-button",
    variant === "primary" ? null : `fune-button--${variant}`,
    loading ? "fune-button--loading" : null,
    className || null,
  ]
    .filter(Boolean)
    .join(" ");
  function press(event: MouseEvent<HTMLButtonElement>): void {
    if (loading) {
      event.preventDefault();
      return;
    }
    onClick?.();
  }
  return (
    <button
      className={classes}
      id={id}
      type={props.type ?? "submit"}
      name={name}
      value={value}
      disabled={disabled}
      aria-disabled={disabled || loading ? true : undefined}
      onClick={press}
    >
      {loading && present(loadingText) ? loadingText : children}
    </button>
  );
}

Install

npm install react react-dom
fune build

With that line in your source, in a TypeScript project (language typescript in fune.project) with React ^19 installed (Functional Weave does not ship it, and fune build stops with the npm install line if it is missing), fune build resolves it and nothing else, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add react.form.button
Download for TypeScript react.form.button-1.0.1-typescript.fune · 13,580 bytes sha256 e622e2d9fcfdbe4c641629d0e7d5d890d9e6031109861b6886ae4d6b437a0b99

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./react.form.button-1.0.1-typescript.fune, or fetch it from a terminal with fune pull react.form.button@1.0.1:typescript.

It is React ^19 · TypeScript only, so there is no package for Python or Rust. The full package is one file too: react.form.button-1.0.1.fune, 13,552 bytes, sha256 bae4ac854d06deca5d39c4edc64fb3bc6e78e1cceb029e73b1a3d026d017213d.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before react.form.button

after — your function gets the result and the arguments, and returns the final result.

// fune: after react.form.button

replace — it requires no other capability, so there is no dependency to replace.

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show react.form.button --steps.

// fune: step react.form.button after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript alone, with the React in tooling/react, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json. A component’s tests are render tests: the props go in, and the HTML renderToStaticMarkup makes of them has to match exactly; a React warning during the render fails the test.

  1. a primary submit button, GOV.UK's default

    <Button id="save">Save and continue</Button>

    renders

    <button class="fune-button" id="save" type="submit">Save and continue</button>
  2. no id given, none rendered

    <Button>Continue</Button>

    renders

    <button class="fune-button" type="submit">Continue</button>
  3. a secondary button

    <Button
      id="find"
      variant="secondary"
      type="button"
    >
      Find address
    </Button>

    renders

    <button class="fune-button fune-button--secondary" id="find" type="button">Find address</button>
  4. a warning button for a destructive action

    <Button id="delete" variant="warning">Delete account</Button>

    renders

    <button class="fune-button fune-button--warning" id="delete" type="submit">Delete account</button>
  5. primary named explicitly has no modifier

    <Button id="pay" variant="primary">Pay</Button>

    renders

    <button class="fune-button" id="pay" type="submit">Pay</button>
  6. a reset button

    <Button id="clear" type="reset" variant="secondary">Clear</Button>

    renders

    <button class="fune-button fune-button--secondary" id="clear" type="reset">Clear</button>
  7. name and value say which submit button was pressed

    <Button
      id="add"
      name="action"
      value="add-another"
      variant="secondary"
    >
      Add another
    </Button>

    renders

    <button class="fune-button fune-button--secondary" id="add" type="submit" value="add-another" name="action">Add another</button>
  8. disabled as GOV.UK renders it: the attribute and aria-disabled

    <Button id="send" disabled>Disabled button</Button>

    renders

    <button class="fune-button" id="send" type="submit" disabled="" aria-disabled="true">Disabled button</button>
  9. loading stays enabled and focusable, aria-disabled, with its loading text

    <Button
      id="send"
      loading
      loadingText="Sending"
    >
      Confirm and send
    </Button>

    renders

    <button class="fune-button fune-button--loading" id="send" type="submit" aria-disabled="true">Sending</button>
  10. loading without loading text keeps the children

    <Button id="send" loading>Confirm and send</Button>

    renders

    <button class="fune-button fune-button--loading" id="send" type="submit" aria-disabled="true">Confirm and send</button>
Show the other 3 tests
  1. loading text is ignored when not loading

    <Button
      id="send"
      loading={false}
      disabled={false}
      loadingText="Sending"
    >
      Confirm and send
    </Button>

    renders

    <button class="fune-button" id="send" type="submit">Confirm and send</button>
  2. a class name comes after the modifiers

    <Button
      id="x"
      variant="warning"
      loading
      className="wide"
    >
      Remove
    </Button>

    renders

    <button class="fune-button fune-button--warning fune-button--loading wide" id="x" type="submit" aria-disabled="true">Remove</button>
  3. text is escaped

    <Button id="x" value="a\"b">Save & <continue></Button>

    renders

    <button class="fune-button" id="x" type="submit" value="a&quot;b">Save &amp; &lt;continue&gt;</button>

More from the author

- **variant**: `primary` (the default, the page's main action), `secondary` (other actions) or `warning`, GOV.UK's red button for an action that destroys something. Other kits call that "danger"; it is `warning` here, as in GOV.UK, and `danger` is not accepted. GOV.UK asks for one primary button per page and very few warning buttons. - **type** is `submit` unless you say `button` or `reset`. It is always written out, so a button inside a form never submits it by surprise. - **name** and **value** are sent with the form when this button submits it, for a form with more than one submit button ("Save" and "Add another"). React writes `value` before `name` in its HTML; the browser does not care. - **disabled** is the real attribute plus `aria-disabled="true"`, as GOV.UK renders it. GOV.UK advises against disabled buttons: they have poor contrast and give no reason. - **loading** is this component's answer to GOV.UK's "Stop users from accidentally sending information more than once". GOV.UK ignores a second click within a second (`data-prevent-double-click`); here the app says when the work is under way. The button stays enabled, so it keeps focus and is still announced, but carries `aria-disabled="true"` and `fune-button--loading`, and a press does nothing: `onClick` is not called and the event's default (submitting the form) is prevented. `loadingText` replaces the children meanwhile. - **onClick** is called with no arguments, never the event. A disabled button never fires it. - **id** is rendered only when you give one: nothing refers to a button by id, so unlike the fields it does not fall back to `useId()`.

It listens for clicks, so it is a client component (`"use client"`). What a press does cannot be rendered on a server; the vectors pin the markup of every state, and the rule for a press (ignored while `loading`) is the four lines in `press`.

Classes: `fune-button`, `fune-button--secondary`, `fune-button--warning`, `fune-button--loading`.

Sources: GOV.UK Design System, "Button" https://design-system.service.gov.uk/components/button/ (default, secondary, warning and disabled buttons, and "Stop users from accidentally sending information more than once").

## Notices

Portions derived from GOV.UK Frontend (https://github.com/alphagov/govuk-frontend), Copyright (c) 2017 Crown Copyright (Government Digital Service), under the MIT License; the full notice is in NOTICE.

1.0.1 adds its attribution notices (NOTICE). The code and the tests are unchanged.

Files

PathBytes
NOTICE1,215
README.md3,159
impl/typescript.tsx1,511
vectors.json3,344