FUNSTACK UI

HomeWhyGetting startedConceptsComponentsRoadmap
GitHub

FUNSTACK UI is in beta. Part of the FUNSTACK family with FUNSTACK Router and FUNSTACK Static, which build this site.

Introduction

  • Why FUNSTACK UI
  • Overview
  • Getting started

Concepts

  • Action props
  • Pending & optimistic state
  • Transitions & ViewTransition
  • Suspense
  • Browser-owned state
  • Server Components

Guides

  • Replacing the element (render)
  • Direction and locales
  • Experimental features
  • Next.js App Router
  • React Router framework mode
  • Content Security Policy
  • Using with AI agents

Components

  • Buttons
    • Button
    • Toggle
    • ToggleGroup
    • Toolbar
  • Disclosure
    • Tabs
    • Accordion
    • Collapsible
    • NavigationMenu
  • Overlays
    • Tooltip
    • HoverCard
    • Popover
    • Dialog
    • AlertDialog
    • Drawer
    • Menu
    • Context menu (Menu)
    • Menubar (Menu)
    • Toast
  • Forms
    • Field and Form
    • Checkbox
    • CheckboxGroup
    • RadioGroup
    • Switch
    • Select
    • Combobox
    • MultiSelect
    • Slider
    • NumberField
    • OTPField
    • TextField
  • Output
    • Progress
    • Meter
    • Avatar
  • Layout
    • Separator
    • Scroll areas (recipe)

Resources

  • Roadmap & changelog
  • GitHub ↗

CheckboxGroup

A group of checkboxes sharing one value, a set of strings: a <fieldset> of real <input type="checkbox"> elements with a shared name. The platform supplies the keyboard, labels, forms and validation. The library adds the set-valued state changed through valueChangeAction in a transition (optimistic, with data-pending), a mixed-state Parent box that checks or unchecks a subset (the WAI-ARIA "select all"), and an "at least one" required.

Toppings
saved toppings: cheese
Show code
CheckboxGroupToppings.tsx
"use client";
import { startTransition, useId, useRef, useState } from "react";
import { CheckboxGroup } from "@funstack/ui/checkbox-group";
import type { CheckboxGroupValueChangeDetails } from "@funstack/ui/checkbox-group";
import { fakeSave } from "./fake-api.js";

const toppings = [
  { value: "cheese", label: "Cheese" },
  { value: "ham", label: "Ham" },
  { value: "olives", label: "Olives" },
  { value: "basil", label: "Basil" },
];

/** The functional update keyed by what changed: overlapping saves can never lose a change. */
function applyChange(prev: readonly string[], change: CheckboxGroupValueChangeDetails) {
  return [
    ...prev.filter((v) => !change.removed.includes(v)),
    ...change.added.filter((v) => !prev.includes(v)),
  ];
}

// Controlled, "update on success": the parent adopts a change only after its save resolves. The
// Parent box derives its checked / mixed state from the Items' optimistic state and its click
// follows the APG cycle: mixed → all → none → the last combination that was saved → … Every
// click is one `valueChangeAction` with `added` / `removed`. A failed save is caught and not
// adopted, so the boxes roll back (the Parent to mixed) when it settles. `aria-controls` on the
// Parent lists the boxes it controls, as in the APG mixed-state example (it passes through).
export function CheckboxGroupToppings() {
  const idPrefix = useId();
  const itemId = (value: string) => `${idPrefix}-${value}`;
  const [selected, setSelected] = useState<string[]>(["cheese"]);
  // Read from a ref: state set inside a pending transition is not visible to a second click.
  const failNext = useRef(false);
  const [failNextShown, setFailNextShown] = useState(false);
  const [error, setError] = useState<string | null>(null);

  return (
    <>
      <CheckboxGroup.Root
        className="demo-checkbox-group"
        value={selected}
        valueChangeAction={async (next, details) => {
          setError(null);
          const fail = failNext.current;
          failNext.current = false;
          if (fail) setFailNextShown(false);
          try {
            await fakeSave(`[${next.join(", ")}]`, { fail });
            startTransition(() => setSelected((prev) => applyChange(prev, details)));
          } catch (e) {
            startTransition(() => setError(e instanceof Error ? e.message : String(e)));
          }
        }}
      >
        <CheckboxGroup.Label>
          {({ pending }) => (
            <>Toppings {pending && <span className="demo-checkbox-group-saving">saving…</span>}</>
          )}
        </CheckboxGroup.Label>
        <label className="demo-field">
          <CheckboxGroup.Parent
            values={toppings.map((t) => t.value)}
            aria-controls={toppings.map((t) => itemId(t.value)).join(" ")}
            className="demo-checkbox"
          />
          All toppings
          <span className="demo-spinner demo-checkbox-group-spinner" aria-hidden />
        </label>
        {toppings.map((topping) => (
          <label key={topping.value} className="demo-field demo-nested">
            <CheckboxGroup.Item
              id={itemId(topping.value)}
              value={topping.value}
              className="demo-checkbox"
            />
            {topping.label}
            <span className="demo-spinner demo-checkbox-group-spinner" aria-hidden />
          </label>
        ))}
      </CheckboxGroup.Root>
      <div className="demo-row demo-options">
        <label className="demo-field">
          <input
            type="checkbox"
            checked={failNextShown}
            onChange={(e) => {
              failNext.current = e.target.checked;
              setFailNextShown(e.target.checked);
            }}
          />
          Make the next save fail
        </label>
      </div>
      <output className="demo-readout">
        saved toppings: <code>{selected.join(", ") || "none"}</code>
        {error && <span className="demo-inline-error"> {error}</span>}
      </output>
    </>
  );
}
checkbox-group.css
/* CheckboxGroup: the Root is a <fieldset>, the Label its <legend>. Items and Parents are styled
   with `.demo-checkbox` from the Checkbox page (checkbox.css): the input is the box, ::before
   draws the check or the dash from [data-checked] / [data-indeterminate]. Both agree with the
   DOM, which holds the optimistic state. */
.demo-checkbox-group {
  display: grid;
  gap: 0.4rem;
  justify-items: start;
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.demo-checkbox-group legend {
  padding-inline: 0.3rem;
  font-weight: 600;
  color: var(--color-text);
}

.demo-checkbox-group[data-pending] {
  cursor: progress;
}

/* An empty required group after a submit attempt (every Item is `required` while empty). */
.demo-checkbox-group:has(.demo-checkbox:user-invalid) legend {
  color: #dc2626;
}

.demo-field:has(.demo-checkbox:disabled) {
  cursor: not-allowed;
}

/* The row spinner shows only next to the boxes whose state is changing. */
.demo-checkbox-group-spinner {
  display: none;
}

.demo-field:has(.demo-checkbox[data-pending]) .demo-checkbox-group-spinner {
  display: inline-block;
}

.demo-checkbox-group-saving {
  font-weight: normal;
  font-size: 0.85em;
  color: var(--color-text-secondary);
}
Async and platform behaviour: Transition types · Optimistic and pending · Suspense · Browser-owned state · Before hydration

Anatomy

import { CheckboxGroup } from "@funstack/ui/checkbox-group";

<CheckboxGroup.Root name="toppings" defaultValue={["cheese"]} valueChangeAction={saveToppings}> {/* fieldset */}
  <CheckboxGroup.Label>Toppings</CheckboxGroup.Label>   {/* legend: optional, first child */}
  <label>
    <CheckboxGroup.Parent values={["cheese", "ham"]} /> All toppings  {/* mixed-state box */}
  </label>
  <label>
    <CheckboxGroup.Item value="cheese" /> Cheese          {/* input type=checkbox */}
  </label>
  <label>
    <CheckboxGroup.Item value="ham" /> Ham
  </label>
</CheckboxGroup.Root>
  • Root is a <fieldset> with its native role group: the legend names it, disabled reaches every box natively, and it finds the form for resets. A render element must stay a <fieldset>.
  • Label is the <legend> and must be the Root's first child. Its function children receive the Root's state.
  • Item is one checkbox of the group: checked while its value is in the set. A plain Checkbox inside the Root is not a member; membership is explicit through Item.
  • Parent is a "select all" box over the values you give it: checked when all are, mixed when some are, and its click sets them all. It has no name, so it is never submitted. Several Parents may share a group, one per section; one listing every value acts as a grand-parent.
  • No Indicator part: style the inputs (the example uses appearance: none and ::before, see the Checkbox page) or use accent-color.

How it works

The value is a set

value and defaultValue are readonly string[], so a useState<string[]> setter plugs in, and so does an as const list. Order does not matter and duplicates are ignored. next is a fresh array in the document order of the Items (what formData.getAll(name) returns); compare it as a set. details.added and details.removed say what changed: one value for an Item click, a whole subset for a Parent click, the diff for a form reset. A value with no Item is kept through clicks and never submitted.

Controlled and updating after the save? Use the diff

Two overlapping saves can complete out of order, and setValue(next) after the await would then land the older whole set last. Update from added / removed instead:

valueChangeAction={async (next, { added, removed }) => {
  await save(added, removed);
  startTransition(() =>
    setToppings((prev) => [
      ...prev.filter((v) => !removed.includes(v)),
      ...added.filter((v) => !prev.includes(v)),
    ]),
  );
}}

Uncontrolled groups need none of this: once every overlapping save has settled, the group commits each change whose save resolved, in click order, and leaves out one whose save rejected.

One exception, in both modes: a form reset (reason: "platform" with details.event?.type === "reset") replaces the whole value, so save its next whole. Its added / removed are only the diff from what was intended and can be empty, for example when a pending uncheck is reset away. If your saves must not overlap at all, queue them with React's useActionState and call its dispatch from the action.

valueChangeAction={async (next, details) => {
  if (details.reason === "platform" && details.event?.type === "reset") await saveAll(next);
  else await save(details.added, details.removed);
}}

Props

CheckboxGroup.Root

PropTypeDefaultDescription
valuereadonly V[]–Controlled checked values; [] checks nothing. undefined means uncontrolled. Order is not significant; duplicates are ignored. V is the item value type: a declared union you pass is kept, a literal is string (Typed values).
defaultValuereadonly V[][]Initial values in uncontrolled mode. Also what a form reset returns to: the latest value is mirrored into the boxes' defaultChecked.
valueChangeActionChangeAction<V[], CheckboxGroupValueChangeDetails<V>>–Runs in the Root's transition whenever the set changes; sync, async or a Server Function. Rejections reach the nearest Error Boundary and roll the change back. details is { reason, added, removed, valid } (plus the virtual event): reason is "activate" for an Item or Parent click and "platform" for a form reset or a change found at hydration; valid: the group would be valid with the next set ("at least one" and the Field's validate, see details.valid).
namestringuseId()The name shared by every Item: the form data key (formData.getAll(name)). Pass a real name inside a form you submit.
requiredbooleanfalseAt least one enabled Item must be checked: every Item is rendered required while no enabled Item is checked, none once one is (see Forms).
disabledbooleanfalseRenders <fieldset disabled>: every Item and Parent is disabled and unfocusable.
readOnlybooleanfalseThe checked boxes stay as they are, or the enclosing Field.Root's: every Item and Parent stays focusable and the group is submitted, but no click, Space or label toggles a box (each click is cancelled, so no input or change fires) and nothing dispatches; a Parent's checked / mixed state still follows the set. Renders aria-readonly="true" on every Item and Parent (the group role has no such state) and data-readonly on every part; the computed "at least one" required is not rendered. Boxes clicked before hydration are put back at mount.
formstring–The form attribute, applied to the fieldset and to every Item.
classNamestring | ((state: CheckboxGroupRootState) => string | undefined)–A class name, or a function of the part's state.
styleCSSProperties | ((state: CheckboxGroupRootState) => CSSProperties | undefined)–Inline style, or a function of the part's state.
childrenReactNode | ((state: CheckboxGroupRootState) => ReactNode)–The Label, Parents and Items. The function form receives the optimistic value; must not suspend.
renderReactElement | ((props, state: CheckboxGroupRootState) => ReactNode)–Replace the default <fieldset> (element form) or take over rendering (function form).
State
CheckboxGroupRootState is { value, pending, disabled, invalid, required, readOnly }; value is the optimistic set as an array in the Items' document order as of the Root's last render (Items reordered by a component that re-renders without the Root are picked up at its next render; next always reads the current order); invalid is true while the enclosing Field.Root shows an error (data-invalid), false outside a Field; required is the prop or the Field's.
Owned
disabled, form, data-pending, data-disabled, data-readonly; no role is written. Inside a Field.Root also aria-labelledby, aria-describedby, aria-invalid and data-invalid.

Other fieldset props pass through (aria-label for a group without a Label, for example). In development a group with no accessible name (no Label, Field.Label, aria-label or aria-labelledby) logs a warning. A disabled group (its own prop or the Field's) is not submitted.

CheckboxGroup.Label

PropTypeDefaultDescription
classNamestring | ((state: CheckboxGroupLabelState) => string | undefined)–A class name, or a function of the part's state.
styleCSSProperties | ((state: CheckboxGroupLabelState) => CSSProperties | undefined)–Inline style, or a function of the part's state.
childrenReactNode | ((state: CheckboxGroupLabelState) => ReactNode)–Content, or a function of the Root's state.
renderReactElement | ((props, state: CheckboxGroupLabelState) => ReactNode)–Replace the default <legend> (element form) or take over rendering (function form).
State
CheckboxGroupLabelState, an alias of CheckboxGroupRootState.
Owned
none.

CheckboxGroup.Item

PropTypeDefaultDescription
valueV–Required. The value this box contributes when checked; unique within the Root. Submitted as the form value. V is string unless you pass a type argument, which checks the value (Typed values).
disabledbooleanfalseNative disabled: unfocusable, never dispatches, not validated. A Parent leaves it alone, and checked it does not satisfy required.
classNamestring | ((state: CheckboxGroupItemState) => string | undefined)–A class name, or a function of the part's state.
styleCSSProperties | ((state: CheckboxGroupItemState) => CSSProperties | undefined)–Inline style, or a function of the part's state.
renderReactElement | ((props, state: CheckboxGroupItemState) => ReactNode)–Replace the default <input> (element form) or take over rendering (function form). It must keep an <input>; the library sets type="checkbox".
State
CheckboxGroupItemState is { value, checked, pending, disabled, readOnly }; checked is optimistic; pending is true while an action is in flight and this box's optimistic state differs from the committed one (click a box twice quickly and it is not pending, the Root still is); disabled includes Root disabled.
Owned
type, name, value, checked, defaultChecked (never rendered), disabled, form, required (computed by the Root; not rendered while read-only), aria-readonly (the Root's read-only), data-checked, data-pending, data-disabled, data-readonly; aria-checked and readOnly are removed; onChange is merged. Inside a Field.Root also aria-invalid.

id, role and other input props pass through. There is no per-Item required: use a plain Checkbox for "this box must be checked". readOnly is not accepted (a type error: it belongs to the Root) and there is no transition prop: animate the check with CSS on :checked.

CheckboxGroup.Parent

PropTypeDefaultDescription
valuesreadonly V[]–Required. The values this Parent controls, usually every Item's value. Values whose Items are disabled are left alone (see Click cycle); values with no Item are still added and removed. V is string unless you pass a type argument, which checks the value (Typed values).
disabledbooleanfalseNative disabled: unfocusable, never dispatches.
classNamestring | ((state: CheckboxGroupParentState) => string | undefined)–A class name, or a function of the part's state.
styleCSSProperties | ((state: CheckboxGroupParentState) => CSSProperties | undefined)–Inline style, or a function of the part's state.
renderReactElement | ((props, state: CheckboxGroupParentState) => ReactNode)–Replace the default <input> (element form) or take over rendering (function form). It must keep an <input>; the library sets type="checkbox".
State
CheckboxGroupParentState is { values, checked, indeterminate, pending, disabled, readOnly }; checked: every value is in the optimistic set (false for empty values); indeterminate: some but not all, never together with checked, and, unlike a plain Checkbox, not hidden while pending (it is derived from the optimistic set, so the DOM property, the attribute and :indeterminate always agree); pending: an action is in flight and one of its values is changing.
Owned
type, checked, defaultChecked, indeterminate (the property is set), disabled, autoComplete ("off": it is not a value, so a browser restoring form state on reload must not restore it), aria-readonly (while the Root is read-only), data-checked, data-indeterminate, data-pending, data-disabled, data-readonly; name, value, form, required, readOnly and aria-checked are removed; onChange is merged.

Other props pass through, such as aria-controls with the ids of the boxes it controls (as in the example above). readOnly is not accepted (a type error: it is the Root's) and there is no transition prop.

Click cycle

The Parent follows the WAI-ARIA APG mixed-state checkbox example:

Parent showsClickdetails
mixedChecks every value.added: the missing values
checkedUnchecks every value.removed: all its values
unchecked, after a partial combination was savedRestores that combination.added: the remembered values
unchecked, no saved partialChecks every value.added: all its values

The remembered combination is the last partial one the group committed (the mount-time value counts), never a state that was only pending and then rolled back. From "none", a user who wants "all" after a remembered combination clicks twice.

Disabled Items are left alone. "Its values" above are the values whose Items are enabled: a click never checks or unchecks a disabled Item (its own disabled prop), and the checked / mixed / unchecked state is derived without them, so a Parent shows checked when every enabled Item is, whatever the disabled ones hold. Values with no Item count as enabled. When every value has only disabled Items, the Parent acts on all of them; disable the Parent to make it inert. Root disabled disables everything and does not change the derivation. The server cannot know which Items are disabled, so the server-rendered Parent counts them until the Items hydrate.

Data attributes

AttributeOnPseudo-classMeaning
data-pendingRoot–valueChangeAction is in flight.
data-pendingItem, Parent–An action is in flight and this box's (or one of the Parent's values') state is changing.
data-checkedItem, Parent:checkedOptimistic checked state; the DOM holds it.
data-indeterminateParent:indeterminateSome but not all of its values are checked. The attribute also works before hydration.
data-disabledRoot, Item, Parent:disabledDisabled by prop; on an Item or Parent, by its own prop or Root disabled.
data-readonlyRoot, Item, Parent–The Root's readOnly (or the Field's). :read-only matches every checkbox, so it tells nothing.
–Item:required, :user-invalid, :focus-visiblePlatform only; no attribute.
.box:checked::before { scale: 1; }      /* flips on click, reverts on rejection */
.box[data-indeterminate]::before { /* the dash */ }
.box[data-pending] { animation: pulse 1s infinite alternate; }
.group[data-pending] { cursor: progress; }
.group:has(.box:user-invalid) legend { color: red; }  /* empty required group after a submit */

Keyboard and ARIA

Everything here is the browser's; the library installs no key handler.

KeyBehaviourDispatches
Tab / Shift+TabEvery enabled Item and Parent is a Tab stop, in document order.no
SpaceToggles the focused box (a Parent follows the click cycle).yes
Read-onlySpace, a click and a label click toggle nothing; Tab still visits every box.no
EnterSubmits the form (implicit submission).no
Any arrow key / Home / EndNothing (the APG defines no arrow keys for checkboxes).–
  • The fieldset is a group named by its legend, as the APG advises for related checkboxes. The Parent's mixed state reaches assistive technology through the indeterminate property (exposed as aria-checked="mixed"), set after hydration.
  • ARIA does not allow aria-required on role group, so a required group is not announced as such on the fieldset: say it in the Label ("choose at least one") or through aria-describedby on the Root. While no enabled box is checked, every box carries native required, which engines expose differently (Chromium's accessibility tree marks the boxes invalid, not required), so the Label or description is the reliable announcement.
  • The checked state assistive technology reads is the optimistic one. A rollback is silent; add an aria-live region if a slow action may fail. The library never moves focus.

Transition types

Concept: Transitions & ViewTransition

fsui-checkbox-group, plus fsui-checkbox-group-check when a dispatch checks something and fsui-checkbox-group-uncheck when it unchecks something (a reset can carry both). No part has a transition prop: a consumer's own <ViewTransition> keys a type map on them.

Optimistic and pending

Concept: Pending & optimistic state

Items and the Parent render the optimistic set into their native inputs. data-pending is on the Root while valueChangeAction is in flight, and on each Item (or Parent) whose state is changing.

Walkthrough

  1. Click Ham: the browser checks it; the group dispatches valueChangeAction(["cheese", "ham"], { reason: "activate", added: ["ham"], removed: [] }) in the Root's transition. The Root and the Ham box get data-pending; a Parent over both values shows checked at once.
  2. Resolve: the set is committed (uncontrolled) and the attributes go.
  3. Reject: the optimistic set reverts, React writes checked back, the Parent returns to mixed, and the error reaches the nearest Error Boundary.
  4. Clicks while a save is pending stack: each dispatch is computed from what the user sees. Uncontrolled, once every save has settled, the changes whose saves resolved are committed in click order. An earlier click whose save rejected is left out, and its error goes to reportError rather than the Error Boundary (see Overlapping actions).

Suspense

Concept: Suspense

No content region; nothing the group renders suspends.

Browser-owned state

Concept: Browser-owned state

Native checkboxes: the browser flips them before any JavaScript runs. A form reset and clicks before hydration are dispatched with reason: "platform", once per group. The Parent's mixed state is derived and mirrored to the DOM property.

Before hydration

Concept: Server Components

Native checkboxes: clicking, Space, labels, required and form submission work. On hydration a changed value is reconciled with one valueChangeAction call (reason: "platform"). A mixed Parent is drawn from data-indeterminate but announced as unchecked until hydration; a Parent clicked before hydration counts as "check all" of its values. A required group keeps the server's required attributes until hydration.

Forms

Permissions (choose at least one)
invited with: (not yet)
valueChangeAction calls, latest first: (none yet)
Show code
CheckboxGroupForm.tsx
"use client";
import { startTransition, useState } from "react";
import { useFormStatus } from "react-dom";
import { CheckboxGroup } from "@funstack/ui/checkbox-group";
import type { CheckboxGroupValueChangeDetails } from "@funstack/ui/checkbox-group";
import { fakeSave } from "./fake-api.js";

const permissions = [
  { value: "users:read", label: "Read users", section: "users" },
  { value: "users:write", label: "Edit users", section: "users" },
  { value: "billing:read", label: "Read billing", section: "billing" },
  { value: "billing:write", label: "Edit billing", section: "billing" },
];
const inSection = (section: string) =>
  permissions.filter((p) => p.section === section).map((p) => p.value);

function SubmitButton() {
  const { pending } = useFormStatus();
  return (
    <button type="submit" className="demo-button demo-primary">
      {pending && <span className="demo-spinner" aria-hidden />}
      Invite
    </button>
  );
}

// The boxes post `perm=…` once per checked box (a real `name`; read it with
// `formData.getAll("perm")`). `required` on the Root means "at least one": while nothing is
// checked every box is `required`, so the browser blocks the submit with its own message; once
// one is checked nothing is. Two section Parents control their own values. After the form action
// succeeds React resets the form and the group follows: one "platform" dispatch with the diff.
export function CheckboxGroupForm() {
  const [invited, setInvited] = useState<string[] | null>(null);
  const [log, setLog] = useState<string[]>([]);
  const record = (_next: string[], { reason, added, removed }: CheckboxGroupValueChangeDetails) => {
    const entry = `${reason}: +[${added.join(", ")}] −[${removed.join(", ")}]`;
    setLog((prev) => [entry, ...prev].slice(0, 4));
  };
  return (
    <form
      className="demo-stack"
      action={async (formData) => {
        await fakeSave("the invitation");
        const perms = formData.getAll("perm").map(String);
        startTransition(() => setInvited(perms));
      }}
    >
      <CheckboxGroup.Root
        className="demo-checkbox-group"
        name="perm"
        required
        valueChangeAction={record}
      >
        <CheckboxGroup.Label>Permissions (choose at least one)</CheckboxGroup.Label>
        {["users", "billing"].map((section) => (
          <div key={section} className="demo-stack">
            <label className="demo-field">
              <CheckboxGroup.Parent values={inSection(section)} className="demo-checkbox" />
              All {section}
            </label>
            {permissions
              .filter((p) => p.section === section)
              .map((p) => (
                <label key={p.value} className="demo-field demo-nested">
                  <CheckboxGroup.Item value={p.value} className="demo-checkbox" />
                  {p.label}
                </label>
              ))}
          </div>
        ))}
      </CheckboxGroup.Root>
      <div className="demo-row">
        <SubmitButton />
        <button type="reset" className="demo-button">
          Reset
        </button>
      </div>
      <output className="demo-readout">
        invited with: <code>{invited === null ? "(not yet)" : JSON.stringify(invited)}</code>
        <br />
        valueChangeAction calls, latest first: <code>{log.join(" · ") || "(none yet)"}</code>
      </output>
    </form>
  );
}
checkbox-group.css
/* CheckboxGroup: the Root is a <fieldset>, the Label its <legend>. Items and Parents are styled
   with `.demo-checkbox` from the Checkbox page (checkbox.css): the input is the box, ::before
   draws the check or the dash from [data-checked] / [data-indeterminate]. Both agree with the
   DOM, which holds the optimistic state. */
.demo-checkbox-group {
  display: grid;
  gap: 0.4rem;
  justify-items: start;
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.demo-checkbox-group legend {
  padding-inline: 0.3rem;
  font-weight: 600;
  color: var(--color-text);
}

.demo-checkbox-group[data-pending] {
  cursor: progress;
}

/* An empty required group after a submit attempt (every Item is `required` while empty). */
.demo-checkbox-group:has(.demo-checkbox:user-invalid) legend {
  color: #dc2626;
}

.demo-field:has(.demo-checkbox:disabled) {
  cursor: not-allowed;
}

/* The row spinner shows only next to the boxes whose state is changing. */
.demo-checkbox-group-spinner {
  display: none;
}

.demo-field:has(.demo-checkbox[data-pending]) .demo-checkbox-group-spinner {
  display: inline-block;
}

.demo-checkbox-group-saving {
  font-weight: normal;
  font-size: 0.85em;
  color: var(--color-text-secondary);
}
  • With a real name, every checked Item posts name=value; read them with formData.getAll(name). Parents post nothing.
  • required means "at least one". HTML has no group constraint, so the Root renders native required on every Item while no enabled Item is checked (following the optimistic state) and on none once one is. A checked disabled Item and a value with no Item do not count: neither is submitted. Validation, the browser's localised message and :user-invalid stay native; the message reads "check this box". Disabled boxes are not validated, so a disabled group never blocks a submit.
  • Before hydration the attribute is whatever the server rendered, and the server cannot know which values have an enabled Item, so it counts any checked value. In an empty required group every box is required, so a user who checks one box and submits before hydration is still blocked by another box until hydration (over-blocking). A group whose only checked values are disabled Items or have no Item renders no required on the server, so a submit before hydration is not blocked (under-blocking, until hydration); validate on the server as well.
  • Form reset (the Reset button, form.reset(), or React's automatic reset after the action succeeds) is one dispatch for the whole group, with reason: "platform", the reset event, and the diff in added / removed. Uncontrolled, the target is the latest defaultValue, and the reset replaces the value whole: it is dispatched even with an empty diff while a change is still pending, so a pending change that fails later cannot bring its box back after the reset. Controlled, the mount-time values are offered to the parent.
  • Clicks before hydration work natively, on Items and on Parents. On hydration the Root dispatches once for everything it finds changed, with no event; a Parent clicked before hydration counts as "check all" (or "uncheck all") of its enabled values. The order of those clicks is not preserved: a Parent click is applied after the Items' state is read, so an Item clicked after the Parent before hydration is overridden by the Parent. Items that hydrate later, inside a Suspense boundary, are reconciled when they do; unlike RadioGroup, a group split across Suspense boundaries works. Firefox restores the Items' checked state on reload, which is reconciled the same way; the Parent is never restored (autocomplete="off"), so a restore cannot be taken for a Parent click.

Server Functions and forms

// Autosave: a per-group action with data-pending, passed directly from a Server Component.
// details ({ reason, added, removed }) is serialisable.
<CheckboxGroup.Root defaultValue={order.toppings} valueChangeAction={saveToppings}>...</CheckboxGroup.Root>

// Native submission: no action on the group; pending is the form's.
<form action={createOrder}>
  <CheckboxGroup.Root name="toppings" required>...</CheckboxGroup.Root>
  <SubmitButton />
</form>

The two channels are independent and may be combined. An action-less group is a working set of native checkboxes before hydration and with JavaScript off; the Parent's cascade and the dynamic required need hydration.

Transition types: every dispatch adds fsui-checkbox-group, plus fsui-checkbox-group-check when it checks something and fsui-checkbox-group-uncheck when it unchecks something (a reset can carry both).