File size: 1,735 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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:

```jsx
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:

```html
<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.