目录

Enable/Disable Control

You can enable or disable a component to control whether it responds to user interactions. When a component is enabled, it can respond to the following events: click event, touch event, drag event, key event, focus event, mouse event, axis event, hover event, accessibility hover event, gesture event, focus axis event, and crown event.

The initial APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.

The enabled attribute takes effect only when the component is pressed. Changes to it during interaction will not be applied.

enabled

enabled(value: boolean): T

Sets whether the component responds to user interactions. If enabled is not set, the component responds to user interactions by default.

Widget capability: Since API version 9, this feature is supported in ArkTS widgets.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value boolean Yes Whether the component responds to user interactions, including clicks and touches. The value true means that the component responds to user interactions, and false means the opposite.

Return value

Type Description
T Current component.

Example

This example demonstrates how to use enabled to set whether a button responds to user interactions.

// xxx.ets
@Entry
@Component
struct EnabledExample {
  build() {
    Flex({ justifyContent: FlexAlign.SpaceAround }) {
      // The button does not respond to clicks.
      Button('disable').enabled(false).backgroundColor(0x317aff).opacity(0.4)
      Button('enable').backgroundColor(0x317aff)
    }
    .width('100%')
    .padding({ top: 5 })
  }
}