Skip to main content

Checkbox

Displays our custom checkbox input implementation.

Props

NameTypeRequiredDefaultDescription
idstringYes-The id of the checkbox
childrenReact.ReactNodeYes-The label of the checkbox
checkedbooleanNo-The checked state of the checkbox
onChange(event: React.ChangeEvent<HTMLInputElement>) => voidNo-The change event handler of the checkbox

Examples

Standalone

Result
Loading...
Live Editor
function ExampleStandalone() {
    const [ checked, setChecked ] = React.useState(false);
    return (
        <Checkbox
            id="checkbox-standalone-001"
            checked={checked}
            onChange={() => setChecked(!checked)}
        >
            Your Label
        </Checkbox>
    )
}

Form element with one checkbox

Result
Loading...
Live Editor
function ExampleFormElementOneCheckbox() {
    const [ values, setValues ] = React.useState({
        'option_001': false
    });
    const setValue = (name, value) => setValues({
        ...values,
        [name]: value
    });
    return (
        <FormElement
            label="Form element with one checkbox"
            component="fieldset"
            labelComponent="legend"
        >
            <Checkbox
                id="checkbox-form-element-single-001"
                checked={values['option_001']}
                onChange={() => setValue('option_001', !values['option_001'])}
            >
                Checkbox 1
            </Checkbox>
        </FormElement>
    );
}

Form element with multiple checkboxes

Result
Loading...
Live Editor
function ExampleFormElementMultipleCheckboxes() {
    const [ values, setValues ] = React.useState({
        'option_001': false,
        'option_002': true
    });
    const setValue = (name, value) => setValues({
        ...values,
        [name]: value
    });
    return (
        <FormElement
            label="Form element with multiple checkboxes"
            component="fieldset"
            labelComponent="legend"
        >
            <Checkbox
                id="checkbox-form-element-multiple-001"
                checked={values['option_001']}
                onChange={() => setValue('option_001', !values['option_001'])}
            >
                Checkbox 1
            </Checkbox>
            <Checkbox
                id="checkbox-form-element-multiple-002"
                checked={values['option_002']}
                onChange={() => setValue('option_002', !values['option_002'])}
            >
                Checkbox 2
            </Checkbox>
        </FormElement>
    );
}

Form element with error

Result
Loading...
Live Editor
function ExampleFormElementError() {
    const [ values, setValues ] = React.useState({
        'option_001': false
    });
    const setValue = (name, value) => setValues({
        ...values,
        [name]: value
    });
    return (
        <FormElement
            label="Form element with one checkbox"
            hasError
            component="fieldset"
            labelComponent="legend"
        >
            <Checkbox
                id="checkbox-form-element-error-001"
                checked={values['option_001']}
                onChange={() => setValue('option_001', !values['option_001'])}
            >
                Checkbox 1
            </Checkbox>
        </FormElement>
    );
}