In certain cases a visible label isn't needed. For example, a checkbox used to select a table row.
If a visible label isn't specified, an aria-label must be provided to the Checkbox for accessibility.
If the field is labeled by a separate element, an aria-labelledby prop must be provided using the id of the labeling element instead.
To internationalize a Checkbox, a localized label should be passed to the children or aria-label prop.
For languages that are read right-to-left (e.g. Hebrew and Arabic), the layout of the checkbox is automatically flipped.
Checkboxes are not selected by default. The defaultSelected prop can be used to set the default state (uncontrolled).
Alternatively, the isSelected prop can be used to make the selected state controlled. See React's documentation on uncontrolled components for more info.
A Checkbox can be in an indeterminate state, controlled using the isIndeterminate prop.
This overrides the appearance of the Checkbox, whether selection is controlled or uncontrolled.
The Checkbox will visually remain indeterminate until the isIndeterminate prop is set to false, regardless of user interaction.
Checkboxes accept a user defined onChange prop, triggered whenever the Checkbox is clicked.
The example below uses onChange to alert the user to changes in the checkbox's state.
functionExample(){let[selected, setSelection]=React.useState(false);return(<Flexdirection="column"><CheckboxisSelected={selected}onChange={setSelection}>
Subscribe
</Checkbox><View>{`You are ${selected ?'subscribed':'unsubscribed'}`}</View></Flex>);}
functionExample(){let[selected, setSelection]=React.useState(false);return(<Flexdirection="column"><CheckboxisSelected={selected}onChange={setSelection}>
Subscribe
</Checkbox><View>{`You are ${
selected ?'subscribed':'unsubscribed'}`}</View></Flex>);}
Checkboxes can display a validation state to communicate to the user if the current value is invalid.
Implement your own validation logic in your app and pass "invalid" to the Checkbox via the validationState prop.
<CheckboxvalidationState="invalid">
I accept the terms and conditions
</Checkbox>
<CheckboxvalidationState="invalid">
I accept the terms and conditions
</Checkbox>
<CheckboxvalidationState="invalid">
I accept the terms
and conditions
</Checkbox>
Whether user input is required on the input before form submission.
Often paired with the necessityIndicator prop to add a visual indicator to the input.
Whether to exclude the element from the sequential tab order. If true,
the element will not be focusable via the keyboard by tabbing. This should
be avoided except in rare scenarios where an alternative means of accessing
the element or its functionality via the keyboard is available.