• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Checkbox
2
3The **\<Checkbox>** component is used to enable or disable an option.
4
5>  **NOTE**
6>
7>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8
9## Child Components
10
11Not supported
12
13## APIs
14
15Checkbox(options?: {name?: string,  group?: string })
16
17Since API version 9, this API is supported in ArkTS widgets.
18
19**Parameters**
20
21| Name | Type| Mandatory | Description|
22| --------| --------| ------ | -------- |
23| name    | string | No| Name of the check box.|
24| group   | string | No| Group name of the check box.<br>**NOTE**<br>If not used with the **\<CheckboxGroup>** component, this parameter is invalid.|
25
26## Attributes
27
28In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
29
30
31| Name         | Type| Description|
32| ------------- | ------- | -------- |
33| select        | boolean | Whether the check box is selected.<br>Default value: **false**<br>Since API version 9, this API is supported in ArkTS widgets.|
34| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | Color of the check box when it is selected.<br>Since API version 9, this API is supported in ArkTS widgets.|
35
36## Events
37
38In addition to the [universal events](ts-universal-events-click.md), the following attributes are supported.
39
40| Name                                        | Description                                                    |
41| -------------------------------------------- | ------------------------------------------------------------ |
42| onChange(callback: (value: boolean) => void) | Triggered when the selected status of the check box changes due to a manual operation.<br>- The value **true** means that the check box is selected.<br>- The value **false** means that the check box is not selected.<br>Since API version 9, this API is supported in ArkTS widgets.|
43
44## Example
45
46```ts
47// xxx.ets
48@Entry
49@Component
50struct CheckboxExample {
51
52  build() {
53    Row() {
54      Checkbox({name: 'checkbox1',  group: 'checkboxGroup'})
55        .select(true)
56        .selectedColor(0xed6f21)
57        .onChange((value: boolean) => {
58          console.info('Checkbox1 change is'+ value)
59        })
60      Checkbox({name: 'checkbox2',  group: 'checkboxGroup'})
61        .select(false)
62        .selectedColor(0x39a2db)
63        .onChange((value: boolean) => {
64          console.info('Checkbox2 change is'+ value)
65        })
66    }
67  }
68}
69```
70
71
72![](figures/checkbox.gif)
73