Focus Events

Note:

Currently in the beta phase.

Focus events are triggered when the page focus moves between focusable components. Components can use focus events to handle related logic.

Note:

  • Currently, only triggering via the Tab key or arrow keys on an external keyboard is supported. Keyboard navigation focus movement is not supported in nested scrolling component scenarios.
  • Components with default interaction logic, such as Button and TextInput, are focusable by default. Components like Text and Image are non-focusable by default. In a non-focusable state, focus events cannot be triggered. The focusable attribute must be set to true to enable triggering.
  • For container components with focus capability, such as Stack and Row, if they contain no focusable child components, the container itself cannot receive focus. Configuring onClick or a single-finger tap gesture for such components will implicitly make them focusable.
  • For focus development and component focus capability, refer to the Focus Development Guide.

Import Module

import kit.ArkUI.*

func onFocus(?() -> Unit)

func onFocus(event: ?() -> Unit): T

Function: Triggered when the current component gains focus.

System Capability: SystemCapability.ArkUI.ArkUI.Full

Since: 22

Parameters:

Parameter Type Required Default Description
event ?() -> Unit Yes - Callback function triggered when the current component gains focus.

Return Value:

Type Description
T Returns the generic method interface type.

func onBlur(?() -> Unit)

func onBlur(event: ?() -> Unit): T

Function: Triggered when the current component loses focus.

System Capability: SystemCapability.ArkUI.ArkUI.Full

Since: 22

Parameters:

Parameter Type Required Default Description
event ?() -> Unit Yes - Callback function triggered when the current component loses focus.

Return Value:

Type Description
T Returns the generic method interface type.