Download wp-calypso/client/components/forms/multi-checkbox/README.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/multi-checkbox/README.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/forms/multi-checkbox/README.md
-
curl -L -o README.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/forms/multi-checkbox/README.md
MultiCheckbox
MultiCheckbox is a React component that can be used in forms to simplify the creation of checkbox inputs where multiple values are possible.
Under the hood, it uses the FormLabel and FormInputCheckbox components.
Example
Below is an example use for the MultiCheckbox component:
const options = [
{ value: 1, label: 'One' },
{ value: 2, label: 'Two' },
];
<MultiCheckbox name="favorite_numbers" options={ options } defaultChecked={ [ 1 ] } />;
This code snippet will generate the following output:
<div>
<label class="form-label"
><input
type="checkbox"
class="form-checkbox"
name="favorite_numbers[]"
value="1"
checked="checked"
/><span>One</span></label
>
<label class="form-label"
><input type="checkbox" class="form-checkbox" name="favorite_numbers[]" value="2" /><span
>Two</span
></label
>
</div>
Props
name
A name to be used as the name field for each checkbox generated. You do not need to suffix the name with "[]".
options
An array of options, of which each is an object containing a value and label string to be displayed alongside the checkbox.
checked
An array of option values to be checked in the rendered set of checkboxes.
defaultChecked
If any values should be checked by default, pass these as an array using the defaultChecked prop.
onChange
Behaves similarly to the equivalent function handler for standard input elements. This function is invoked when the set of selected checkboxes changes, and is passed a single object argument containing value as an array of the newly selected checkbox values.
disabled
Pass true to set each of the rendered checkboxes as disabled.