ts-universal-attributes-enable.md 1.4 KB
Newer Older
Z
zengyawen 已提交
1
# Enable/Disable
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
The **enabled** attribute sets whether a component responds to user interactions, such as [click events](ts-universal-events-click.md), [touch events](ts-universal-events-touch.md), [drag events](ts-universal-events-drag-drop.md), [key events](ts-universal-events-key.md), [focus events](ts-universal-focus-event.md), and [mouse events](ts-universal-mouse-key.md).
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
>  **NOTE**
>
>  The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9

Z
zengyawen 已提交
10 11 12
## Attributes


E
ester.zhou 已提交
13 14
| Name     | Type   | Description                                      |
| ------- | ------- | ---------------------------------------- |
E
ester.zhou 已提交
15
| enabled | boolean | Whether the component responds to user interactions, including clicks and touches. The value **true** means that the component responds to user interactions,<br>and **false** means the opposite.<br>Default value: **true**|
Z
zengyawen 已提交
16 17 18 19


## Example

E
ester.zhou 已提交
20 21
```ts
// xxx.ets
Z
zengyawen 已提交
22 23 24
@Entry
@Component
struct EnabledExample {
E
ester.zhou 已提交
25
  
Z
zengyawen 已提交
26 27
  build() {
    Flex({ justifyContent: FlexAlign.SpaceAround }) {
E
ester.zhou 已提交
28
      // The component does not respond to clicks.
Z
zengyawen 已提交
29 30 31 32 33 34 35 36 37
      Button('disable').enabled(false).backgroundColor(0x317aff).opacity(0.4)
      Button('enable').backgroundColor(0x317aff)
    }
    .width('100%')
    .padding({ top: 5 })
  }
}
```

Z
zengyawen 已提交
38
![en-us_image_0000001212218428](figures/en-us_image_0000001212218428.gif)