ts-basic-components-checkbox.md 1.7 KB
Newer Older
E
esterzhou 已提交
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
# Checkbox

> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.


The **\<Checkbox>** component is used to enable or disable an option.

## Required Permissions

None

## Child Components

None

## APIs

Checkbox( name?: string,  group?: string )

- Parameters
  | Name | Type| Mandatory | Default Value| Description|
  | --------| --------| ------ | -------- | -------- |
  | name    | string | No| - | Name of the check box.|
  | group   | string | No| - | Group name of the check box.|


## Attributes


| Name         | Type| Default Value| Description|
| ------------- | ------- | ------ | -------- |
| select        | bool   | false | Whether the check box is selected.|
| selectedColor | Color | - | Color of the check box when it is selected.|

## Events

E
esterzhou 已提交
38
| Name     | Description|
E
esterzhou 已提交
39
| ----------| -------- |
E
esterzhou 已提交
40 41
|onChange(callback: (value: boolean) => void) | Triggered when the selection status of the check box changes.<br>- The value **true** means that the check box is selected.<br>- The value **false** means that the check box is not selected.|

E
esterzhou 已提交
42 43 44
## Example

```
E
esterzhou 已提交
45
@Entry
E
esterzhou 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
@Component
struct CheckboxExample {

  build() {
    Row() {
      Checkbox({name: 'checkbox1',  group: 'checkboxGroup'})
        .select(true)
        .selectedColor(0xed6f21)
        .onChange((value: boolean) => {
          console.info('Checkbox1 change is'+ value)
        })
      Checkbox({name: 'checkbox2',  group: 'checkboxGroup'})
        .select(false)
        .selectedColor(0x39a2db)
        .onChange((value: boolean) => {
          console.info('Checkbox2 change is'+ value)
        })
    }
  }
}
```


![](figures/checkbox.gif)