Checkboxes are used for a list of options when a user can select more than one option. Checkboxes can also be used to turn an option on and off.
npm install @nib-components/checkbox
As a form input, @nib-components/form-control must wrap this component to provide an accessible label, help text, and validation styling. Note: You will also need to install the peerDependencies @nib/icons and @nib-components/theme.
import Checkbox from '@nib-components/checkbox';
<Checkbox/> is wrapped in a
<FormControl/>, all FormControl props such as
disabled will be passed down to this component. This includes the
label which will align with the
for attribute on the
All props passed directly to
<Checkbox/> will be applied to the underlying
<input> as attributes.
|The checkbox input value.
|The checkbox input label.
|The checkbox input subtitle.
|Whether the label is bold. If subtitle is provided, the default value changes to
|Whether the input is selected.
The user can select the checkbox by clicking the checkbox directly or by clicking on its label. Therefore links cannot be included in checkbox labels. The target container height for each checkbox option is 56px. This large target size makes it easy for users to select/unselect the option, even if they are using a touch screen device or have limited dexterity.
By default, all checkboxes are unchecked. Requiring the user to select the relevant options reduces data entry errors.
On desktop and ipad devices the length of the checkbox option container will be dependant on the length of the text; the container padding remains the same.
Checkbox options are displayed inline by default. This can be toggled via the
On mobile and small screens (480px of less) checkbox options are full-width and stacked. This allows users to easily reach and select options.
Labels help the user understand what options to select. Labels are short, concise and use sentence-style capitalisation.
Denote optional controls by adding “(Optional)" to the end of the label.
We would like to add an "optional" prop to our "FormControl" that appends this string automatically to ensure consistency.
If you'd like to help with this we would welcome a PR.
Help text is an instruction that supports a user to make an accurate selection. It can also be used to clarify how the information will be used. It is optional and should only be used where needed.
Help text should appear below the label and above the checkbox options. Use sentence-style capitalisation and concise sentence/s.
Help text displayed above the checkbox options allows screen readers to read the help information before the user makes a selection.
Subtitles are an optional prop to provide more context to the option. Subtitles should be added to all options in the group, or none. Otherwise, alignment will suffer, especially if rendering the options inline.