BridgeBeta
  • Brand
  • Digital Assets
    Foundations
    Icons
    Components
    Templates
  • Resources
    Design Tokens
    How-tos
    Best Practices
    Libraries
    Accessibility
    Products List
  • Support
    • Overview
    • Actions
      • Overview
      • Button
      • ContextMenu
      • Link
    • Controls
      • Overview
      • Checkbox
      • Tag
      • Toggle
    • Forms
      • Overview
      • DatePicker
      • FileUploader
      • Input
      • NumberInput
      • RadioButton
      • Search
      • Select
      • Slider
      • TextArea
      • TextInput
    • Hooks
      • useIsomorphicLayoutEffect
      • useMediaQuery
      • useSettings
    • Navigation
      • Overview
      • AnchorNavigation
      • BannerNavigation
      • Breadcrumb
      • Footer
      • InfoBar
      • MainNavigation
      • SecondaryNavigation
      • StepNavigation
      • SubNavigation
    • Overlay
      • Overview
      • Credits
      • Modal
      • ModalWrapper
      • Notification
      • Tooltip
    • Structure
      • Overview
      • Accordion
      • AuthLayout
      • Avatar
      • Callout
      • Card
      • ContentSwitcher
      • Empty
      • Hero
      • InlineLoading
      • Item
      • List
      • Loading
      • mdxComponents
      • Module
      • Pagination
      • ReadMore
      • Story
      • Table
      • Tabs
      • Text
      • Unit
      • User
      • WFPCoreProvider
      • Wrapper
Components
Controls
Checkbox

Checkbox

  • Design
  • Code
  • Props

Checkboxes are used for multiple choices, not for mutually exclusive choices.

Import statement

import { Checkbox } from "@wfp/react"

Editable Example

<Checkbox id="check-1" labelText="Label text" />;

Grouping

Horizontal

Editable Example

<InputGroup
  labelText="Input group"
  helperText="Describing the input group"
>
  <Checkbox id="check-1" labelText="Option 1" />
  <Checkbox id="check-2" labelText="Option 2" />
  <Checkbox id="check-3" labelText="Option 3" />
</InputGroup>;

Vertical

Editable Example

<InputGroup
  labelText="Input group"
  helperText="Describing the input group"
  vertical
>
  <Checkbox id="check-1" labelText="Option 1" />
  <Checkbox id="check-2" labelText="Option 2" />
  <Checkbox id="check-3" labelText="Option 3" />
</InputGroup>;

Expand code

Editable Example

const FormExample = () => {
  const [defaultValues, setDefaultValues] = useState(
    {}
  );
  const {
    control,
    register,
    handleSubmit,
    watch,
    reset,
  } = useForm({ defaultValues });
  const [data, setData] = useState({});

  const setDefaultValuesFunc = (e) => {
    console.log(e.target.value);
    try {
      const values = JSON.parse(e.target.value);
      setDefaultValues(values);
    } catch (e) {
      console.log(e);
    }
  };

  const resetInputs = () => {
    reset(defaultValues);
  };
  const currentValues = watch();

  return (
    <>
      <form
        onSubmit={handleSubmit((data) =>
          setData(data)
        )}
      >
        <InputGroup
          labelText="Input group"
          helperText="Describing the input group"
        >
          <Checkbox
            id="1"
            name="check-1"
            labelText="Option 1"
            {...register("check-1")}
          />
          <Checkbox
            id="2"
            name="check-2"
            labelText="Option 2"
            {...register("check-2")}
          />
        </InputGroup>
        <Button type="submit">Submit</Button>{" "}
        <Button onClick={resetInputs} kind="secondary">
          Reset here
        </Button>
        <div className="debug">
          <h4>Submitted form data</h4>
          <pre>{JSON.stringify(data, null, 2)}</pre>

          <h4>Current values</h4>
          <pre>
            {JSON.stringify(currentValues, null, 2)}
          </pre>

          <TextInput
            labelText="Default values (editable)"
            defaultValue={JSON.stringify(
              defaultValues
            )}
            onChange={setDefaultValuesFunc}
          />
        </div>
      </form>
    </>
  );
};

render(<FormExample />);

Behaviour

Checkbox States

The checkbox control allows for three states: selected, unselected, and indeterminate. The indeterminate state comes into play when the checkbox contains a sublist of selections, some of which are selected, and some unselected.

Invalid

When the checkbox is in an invalid state, the user will be notified by an error message.

Editable Example

<Checkbox
  id="check-invalid"
  labelText="Accept terms and conditions"
  invalid
  invalidText="Please accept the terms and conditions"
/>;

Actions

Click target

Users should be able to select the checkbox by clicking on the box directly or by clicking on its label.

Default selection

The default view of a set of checkboxes is having no option selected.

Formatting

  • Checkbox input(1): It indicates the checkbox state. By default it is set to unselected.

  • Checkbox label(2): Describes the information you want to select or unselect.

Related

RadioButton

Reference

Carbon Design System Usage for checkboxes

On this page

  • Grouping
  • Horizontal
  • Vertical
  • Behaviour
  • Checkbox States
  • Invalid
  • Actions
  • Click target
  • Default selection
  • Formatting
  • Related
  • Reference

References

  • Storybook
Storybook
Figma library
Contact us
2025 © World Food Programme