Form.Checkbox
A simple checkbox for use with Form.CheckboxSet
.
Note: extra props added to this component are passed as attributes to the
underlying input
node. See MDN for documentation on available
input attributes.
Controlled Standalone Usage
Any Paragon component or export may be added to the code example.
Unlabeled control
Any Paragon component or export may be added to the code example.
Controlled Group Usage with useCheckboxSetValues
useCheckboxSetValues(initialValues[])
returns an array: [state, dispatchers]
.
dispatchers
includes add(value)
remove(value)
set(values[])
and clear()
Any Paragon component or export may be added to the code example.
Uncontrolled Usage
Any Paragon component or export may be added to the code example.
Indeterminate Usage
Any Paragon component or export may be added to the code example.
Inline layout
Any Paragon component or export may be added to the code example.
Validation
Group Level Validation
Any Paragon component or export may be added to the code example.
Individual option validation
Any Paragon component or export may be added to the code example.
Label Position
The label is positioned to the right of the checkbox control by default. The label can be rendered on the left instead
by passing the floatLabelLeft
prop.
Any Paragon component or export may be added to the code example.
Theme Variables#
CSS Variable | Computed Value |
---|---|
| |
| |
| |
| |
| |
Props API#
- id
string
Specifies id of the FormCheckbox component.
- children
node
RequiredSpecifies contents of the component.
- className
string
Specifies class name to append to the base element.
- controlClassName
string
Specifies class name for control component.
- labelClassName
string
Specifies class name for label component.
- description
node
Specifies description to show under the checkbox.
- isInvalid
bool
DefaultfalseSpecifies whether to display checkbox in invalid state, this affects styling.
- isValid
bool
DefaultfalseSpecifies whether to display checkbox in valid state, this affects styling.
- controlAs
elementType
DefaultReact.forwardRef( ({ isIndeterminate, ...props }, ref) => { const { getCheckboxControlProps, hasCheckboxSetProvider } = useCheckboxSetContext(); const defaultRef = React.useRef(); const resolvedRef = ref || defaultRef; const { getControlProps } = useFormGroupContext(); let checkboxProps = getControlProps({ ...props, className: classNames('pgn__form-checkbox-input', props.className), }); if (hasCheckboxSetProvider) { checkboxProps = getCheckboxControlProps(checkboxProps); } React.useEffect(() => { // this if(resolvedRef.current) prevents console errors in testing if (resolvedRef.current) { resolvedRef.current.indeterminate = isIndeterminate; } }, [resolvedRef, isIndeterminate]); return ( <input type="checkbox" {...checkboxProps} ref={resolvedRef} /> ); }, )Specifies control element.
- floatLabelLeft
bool
DefaultfalseSpecifies whether the floating label should be aligned to the left.
- disabled
bool
DefaultfalseSpecifies whether the
FormCheckbox
is disabled.
- isIndeterminate
bool
DefaultfalseSpecifies whether the checkbox should be rendered in indeterminate state.
- className
string
Specifies class name to append to the base element.
- children
node
RequiredSpecifies contents of the component.
- className
string
Specifies class name to append to the base element.
- name
string
RequiredSpecifies name for the component.
- value
string
[]
Specifies values for the checkboxes.
- defaultValue
string
[]
Specifies default values for the checkboxes.
- isInline
bool
DefaultfalseSpecifies whether to display components with inline styling.
- onChange
func
Specifies onChange event handler.
- onFocus
func
Specifies onFocus event handler.
- onBlur
func
Specifies onBlur event handler.
Usage Insights#
CheckboxControl
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-admin-portal | 20.46.3 | 2 | |
frontend-app-course-authoring | 21.5.6 | 3 | |
frontend-app-learner-portal-enterprise | 20.45.4 | 2 | |
frontend-lib-content-components | 21.5.6 | 4 |
FormCheckbox
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-account | 20.46.3 | 2 | |
frontend-app-admin-portal | 20.46.3 | 9 | |
frontend-app-authn | 20.46.2 | 3 | |
frontend-app-communications | 20.46.2 | 7 | |
frontend-app-course-authoring | 21.5.6 | 4 | |
frontend-app-discussions | 20.46.3 | 2 | |
frontend-app-gradebook | 20.45.0 | 1 | |
frontend-app-learner-dashboard | 20.46.2 | 1 | |
frontend-app-learner-portal-enterprise | 20.45.4 | 1 | |
frontend-app-library-authoring | 21.5.6 | 4 | |
frontend-app-support-tools | 20.46.0 | 1 | |
frontend-lib-content-components | 21.5.6 | 7 | |
prospectus | 20.46.2 | 1 |
FormCheckboxSet
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-communications | 20.46.2 | 1 | |
frontend-app-course-authoring | 21.5.6 | 2 | |
frontend-app-learner-dashboard | 20.46.2 | 1 | |
frontend-lib-content-components | 21.5.6 | 1 |