1e41f4b71Sopenharmony_ci# Focus Event
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciA focus event is triggered when the page focus moves between components. It can be used to process related logic within the component.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  - The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci>  - Currently, only the Tab button and arrow buttons on the external keyboard can be used to trigger the focus event. Sequential keyboard navigation is not supported for nested scrollable components.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci>  - Components that have default interaction logic, such as [\<Button>](ts-basic-components-button.md) and [\<TextInput>](ts-basic-components-textinput.md), are focusable by default. Other components, such as [\<Text>](ts-basic-components-text.md) and [\<Image>](ts-basic-components-image.md), are not focusable by default. Only focusable components can trigger a focus event. To enable a component to be focusable, set its **focusable** attribute to **true**.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## onFocus
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_cionFocus(event: () => void)
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciTriggered when the current component obtains focus.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## onBlur
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cionBlur(event:() =&gt; void)
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciTriggered when the current component loses focus.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci## Example
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci```ts
33e41f4b71Sopenharmony_ci// xxx.ets
34e41f4b71Sopenharmony_ci@Entry
35e41f4b71Sopenharmony_ci@Component
36e41f4b71Sopenharmony_cistruct FocusEventExample {
37e41f4b71Sopenharmony_ci  @State oneButtonColor: string = '#FFC0CB'
38e41f4b71Sopenharmony_ci  @State twoButtonColor: string = '#87CEFA'
39e41f4b71Sopenharmony_ci  @State threeButtonColor: string = '#90EE90'
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci  build() {
42e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
43e41f4b71Sopenharmony_ci      // You can use the up and down arrow keys on an external keyboard to move the focus between the three buttons. When a button gains focus, its color changes. When it loses focus, its color changes back.
44e41f4b71Sopenharmony_ci      Button('First Button')
45e41f4b71Sopenharmony_ci        .backgroundColor(this.oneButtonColor)
46e41f4b71Sopenharmony_ci        .width(260)
47e41f4b71Sopenharmony_ci        .height(70)
48e41f4b71Sopenharmony_ci        .fontColor(Color.Black)
49e41f4b71Sopenharmony_ci        .focusable(true)
50e41f4b71Sopenharmony_ci        .onFocus(() => {
51e41f4b71Sopenharmony_ci          this.oneButtonColor = '#FF0000'
52e41f4b71Sopenharmony_ci        })
53e41f4b71Sopenharmony_ci        .onBlur(() => {
54e41f4b71Sopenharmony_ci          this.oneButtonColor = '#FFC0CB'
55e41f4b71Sopenharmony_ci        })
56e41f4b71Sopenharmony_ci      Button('Second Button')
57e41f4b71Sopenharmony_ci        .backgroundColor(this.twoButtonColor)
58e41f4b71Sopenharmony_ci        .width(260)
59e41f4b71Sopenharmony_ci        .height(70)
60e41f4b71Sopenharmony_ci        .fontColor(Color.Black)
61e41f4b71Sopenharmony_ci        .focusable(true)
62e41f4b71Sopenharmony_ci        .onFocus(() => {
63e41f4b71Sopenharmony_ci          this.twoButtonColor = '#FF0000'
64e41f4b71Sopenharmony_ci        })
65e41f4b71Sopenharmony_ci        .onBlur(() => {
66e41f4b71Sopenharmony_ci          this.twoButtonColor = '#87CEFA'
67e41f4b71Sopenharmony_ci        })
68e41f4b71Sopenharmony_ci      Button('Third Button')
69e41f4b71Sopenharmony_ci        .backgroundColor(this.threeButtonColor)
70e41f4b71Sopenharmony_ci        .width(260)
71e41f4b71Sopenharmony_ci        .height(70)
72e41f4b71Sopenharmony_ci        .fontColor(Color.Black)
73e41f4b71Sopenharmony_ci        .focusable(true)
74e41f4b71Sopenharmony_ci        .onFocus(() => {
75e41f4b71Sopenharmony_ci          this.threeButtonColor = '#FF0000'
76e41f4b71Sopenharmony_ci        })
77e41f4b71Sopenharmony_ci        .onBlur(() => {
78e41f4b71Sopenharmony_ci          this.threeButtonColor = '#90EE90'
79e41f4b71Sopenharmony_ci        })
80e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 20 })
81e41f4b71Sopenharmony_ci  }
82e41f4b71Sopenharmony_ci}
83e41f4b71Sopenharmony_ci```
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci ![focus](figures/focus.png) 
86