StackForm
Components

CheckboxField

Boolean checkbox field with label, error, hint, and flexible label positioning

CheckboxField renders a labeled, accessible <input type="checkbox"> connected to the active form adapter via context. Error and hint states surface automatically — no prop wiring needed.

Props

PropTypeRequiredDefaultDescription
namestringyesField name. Used as the form state key and to derive element IDs.
labelstringLabel text rendered next to the checkbox.
labelPosition'left' | 'right''right'Position of the label relative to the checkbox input.
hintstringHelper text shown below the checkbox when no error is present.
indeterminatebooleanfalseSets the checkbox to an indeterminate state. Sets aria-checked="mixed". Useful for "select all" patterns.
disabledbooleanfalseDisables the checkbox. Inherits from StackFormProvider if not set.
loadingbooleanfalseReplaces the checkbox with a skeleton shimmer.
requiredbooleanfalseMarks the field as required. Appends * to the label.
classNamesCheckboxFieldClassNamesTailwind class overrides per slot. Stacks with provider and core classes.
slotsCheckboxFieldSlotsComponent overrides per slot. First non-null wins: field → provider → default.
slotProps{ wrapper?, label?, input?, error?, hint? }Extra props passed to each slot. Field-level replaces provider-level per key.
onValueChange(value: boolean) => voidCalled after onChange with the new value.
validate(value: boolean) => string | undefined | Promise<string | undefined>Field-level validator. Runs on blur.

Slots

SlotProp interfaceDescription
WrapperWrapperSlotPropsOuter container element
LabelLabelSlotPropsLabel element
InputCheckboxSlotPropsThe <input type="checkbox"> element
ErrorErrorSlotPropsError message
HintHintSlotPropsHint/helper text

classNames

KeyApplied to
wrapperOuter container
labelLabel element
inputCheckbox input element
errorError message
hintHint text

Examples

With error

Errors surface automatically from the form adapter. Trigger one manually to test:

form.setError('terms', { message: 'You must accept the terms' })

<CheckboxField name="terms" label="I accept the terms and conditions" />

With hint

<CheckboxField
  name="newsletter"
  label="Subscribe to our newsletter"
  hint="Receive updates and offers weekly."
/>

Indeterminate state

Useful for "select all" patterns where a parent checkbox controls multiple children:

const allChecked = childA && childB && childC
const isIndeterminate = !allChecked && (childA || childB || childC)

<CheckboxField
  name="select-all"
  label="Select all items"
  indeterminate={isIndeterminate}
/>

Label on the left

Position the label before the checkbox:

<CheckboxField
  name="subscribe"
  label="Subscribe to updates"
  labelPosition="left"
/>

With slot override

Replace the Label slot with a custom component. Slot components receive only display-level props.

import type { LabelSlotProps } from '@stackform/ui'

function CustomLabel({ htmlFor, children, required }: LabelSlotProps) {
  return (
    <label htmlFor={htmlFor} className="text-sm font-medium text-gray-700">
      {children}
      {required ? <span aria-hidden="true"> *</span> : null}
    </label>
  )
}

<CheckboxField
  name="email-alerts"
  label="Receive email alerts"
  slots={{ Label: CustomLabel }}
/>