React Checkbox Pro

Helper Text & Error States

How to add helper text and handle error states in React Checkbox Pro

Helper Text & Error States

Learn how to add helper text and handle error states in your checkboxes.

Example

This field is required

Please accept the terms

Usage

With Helper Text

<Checkbox helperText="Optional additional information">
  With Helper Text
</Checkbox>

With Error State

<Checkbox 
  error={true}
  errorMessage="This field is required"
  required
>
  Error State
</Checkbox>

Combined with Validation

function ValidatedCheckbox() {
  const [checked, setChecked] = useState(false);
  const [error, setError] = useState(false);
 
  const handleChange = (newChecked: boolean) => {
    setChecked(newChecked);
    setError(!newChecked);
  };
 
  return (
    <Checkbox 
      checked={checked}
      onChange={handleChange}
      error={error}
      errorMessage="You must accept the terms"
      required
    >
      Accept Terms
    </Checkbox>
  );
}

Props

PropTypeDescription
helperTextstringAdditional information displayed below the checkbox
errorbooleanWhether the checkbox is in an error state
errorMessagestringError message displayed when error is true

Best Practices

  1. Use clear and concise helper text
  2. Display error messages that help users fix the issue
  3. Consider using validation on form submission
  4. Keep error messages close to their respective checkboxes
  5. Use consistent error styling across your form

On this page