# Checkbox
### Install
``` javascript
import Vue from 'vue';
import { Checkbox, CheckboxGroup } from 'vant';
Vue.use(Checkbox).use(CheckboxGroup);
```
## Usage
### Basic Usage
```html
Checkbox
```
```javascript
export default {
data() {
return {
checked: true
};
}
};
```
### Disabled
```html
Checkbox
```
### Custom Shape
```html
Checkbox
```
### Custom Color
```html
Checkbox
```
### Custom Icon
Use icon slot to custom icon
```html
Custom Icon
```
```js
export default {
data() {
return {
checked: true,
activeIcon: 'https://img.yzcdn.cn/vant/user-active.png',
inactiveIcon: 'https://img.yzcdn.cn/vant/user-inactive.png'
};
}
};
```
### Checkbox Group
When Checkboxes are inside a CheckboxGroup, the checked checkboxes's name is an array and bound with CheckboxGroup by v-model.
```html
Checkbox a
Checkbox b
Checkbox c
```
```javascript
export default {
data() {
return {
result: ['a', 'b']
};
}
};
```
### Maximum amount of checked options
```html
Checkbox a
Checkbox b
Checkbox c
```
### Toggle All
```html
Checkbox a
Checkbox b
Checkbox c
Check All
Toggle All
```
```js
export default {
data() {
return {
result: []
}
},
methods: {
checkAll() {
this.$refs.checkboxGroup.toggleAll(true);
},
toggleAll() {
this.$refs.checkboxGroup.toggleAll();
}
}
}
```
### Inside a Cell
```html
```
```js
export default {
methods: {
toggle(index) {
this.$refs.checkboxes[index].toggle();
}
}
}
```
## API
### Checkbox Props
| Attribute | Description | Type | Default | Version |
|------|------|------|------|------|
| name | Checkbox name | *any* | - | - |
| shape | Can be set to `square` | *string* | `round` | - |
| v-model | Check status | *boolean* | `false` | - |
| disabled | Disable checkbox | *boolean* | `false` | - |
| label-disabled | Whether to disable label click | *boolean* | `false` | - |
| label-position | Can be set to `left` | *string* | `right` | - |
| icon-size | Icon size | *string \| number* | `20px` | - |
| checked-color | Checked color | *string* | `#1989fa` | - | - |
| bind-group | Whether to bind with CheckboxGroup | *boolean* | `true` | 2.2.4 |
### CheckboxGroup Props
| Attribute | Description | Type | Default | Version |
|------|------|------|------|------|
| v-model | Names of all checked checkboxes | *any[]* | - | - |
| max | Maximum amount of checked options | *number* | `0`(Unlimited) | - |
| disabled | Disable all checkboxes | *boolean* | `false` | - |
| icon-size | Icon size of all checkboxes | *string \| number* | `20px` | 2.2.3 |
| checked-color | Checked color of all checkboxes | *string* | `#1989fa` | - | 2.2.3 |
### Checkbox Events
| Event | Description | Parameters |
|------|------|------|
| change | Triggered when value changed | current value |
| click | Triggered when click checkbox | event: Event |
### CheckboxGroup Events
| Event | Description | Parameters |
|------|------|------|
| change | Triggered when value changed | current value |
### Checkbox Slots
| Name | Description | SlotProps |
|------|------|------|
| default | Custom label | - |
| icon | Custom icon | checked: whether to be checked |
### CheckboxGroup Methods
Use ref to get CheckboxGroup instance and call instance methods
| Name | Description | Attribute | Return value |
|------|------|------|------|
| toggleAll | Toggle check status of all checkboxes | checked?: boolean | - |
### Checkbox Methods
Use ref to get Checkbox instance and call instance methods
| Name | Description | Attribute | Return value |
|------|------|------|------|
| toggle | Toggle check status | checked?: boolean | - |