1# Focus Control
2
3Focus control attributes set whether a component is focusable and how it participates in focus navigation.
4
5>  **NOTE**
6>
7>  - The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8>
9>  - Custom components are inherently unfocusable, and setting [focusable](#focusable) and [enabled](ts-universal-attributes-enable.md#enabled) attributes to **false** or setting the [visibility](ts-universal-attributes-visibility.md#visibility) attribute to **Hidden** or **None** does not impact their child components' capability to gain focus.
10>
11>  - Components can actively acquire focus independently of the window's focus state.
12>
13>  - For details about focus development, see [Focus Event](../../../ui/arkts-common-events-focus-event.md).
14
15## focusable
16
17focusable(value: boolean)
18
19Sets whether the component is focusable.
20
21**Atomic service API**: This API can be used in atomic services since API version 11.
22
23**System capability**: SystemCapability.ArkUI.ArkUI.Full
24
25**Parameters**
26
27| Name| Type   | Mandatory| Description                                                        |
28| ------ | ------- | ---- | ------------------------------------------------------------ |
29| value  | boolean | Yes  | Whether the component is focusable.<br>**NOTE**<br>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](ts-universal-focus-event.md).|
30
31## tabIndex<sup>9+</sup>
32
33tabIndex(index: number)
34
35Sets the Tab order of the component in sequential focus navigation with the **Tab** key.
36
37**Atomic service API**: This API can be used in atomic services since API version 11.
38
39**System capability**: SystemCapability.ArkUI.ArkUI.Full
40
41**Parameters**
42
43| Name| Type  | Mandatory| Description                                                        |
44| ------ | ------ | ---- | ------------------------------------------------------------ |
45| index  | number | Yes  | Tab order of the component in sequential focus navigation with the **Tab** key. When components with positive **tabIndex** values are present, only these components are reachable through sequential focus navigation, and they are navigated cyclically in ascending order based on the **tabIndex** value. When components with positive **tabIndex** values are not present, those components with a **tabIndex** value of **0** are navigated based on the preset focus navigation rule.<br>**tabIndex** is not yet compatible with [UiExtension](../js-apis-arkui-uiExtension.md) component. As such, using **tabIndex** on a page that contains [UiExtension](../js-apis-arkui-uiExtension.md) may lead to disordered focus navigation.<br>- **tabIndex** >= 0: The component is focusable and can be reached through sequential keyboard navigation.<br>- **tabIndex** < 0 (usually **tabIndex** = -1): The component is focusable, but cannot be reached through sequential keyboard navigation.<br>Default value: **0**<br> **NOTE**<br> **tabIndex** and **focusScopeId** cannot be used together.
46|
47
48## defaultFocus<sup>9+</sup>
49
50defaultFocus(value: boolean)
51
52Specifies whether to set the component as the default focus of the page.
53
54**Atomic service API**: This API can be used in atomic services since API version 11.
55
56**System capability**: SystemCapability.ArkUI.ArkUI.Full
57
58**Parameters**
59
60| Name| Type   | Mandatory| Description                                                        |
61| ------ | ------- | ---- | ------------------------------------------------------------ |
62| value  | boolean | Yes  | Whether to set the component as the default focus of the page. This parameter takes effect only when the page is new and accessed for the first time.<br>Default value: **false**<br>**NOTE**<br>The value **true** means to set the component as the default focus, and the value **false** has no effect.<br>If no component on the page has **defaultFocus(true)** set:<br>For API version 11 and earlier, the default focus is on the first focusable non-container component on the page.<br>For API version versions later than 11, the default focus is on the page's root container.<br>If **defaultFocus(true)** is set for multiple components on the page, the first component found in the component tree in-depth traversal is used as the default focus.|
63
64## groupDefaultFocus<sup>9+</sup>
65
66groupDefaultFocus(value: boolean)
67
68Specifies whether to set the component as the default focus of the container.
69
70**Atomic service API**: This API can be used in atomic services since API version 11.
71
72**System capability**: SystemCapability.ArkUI.ArkUI.Full
73
74**Parameters**
75
76| Name| Type   | Mandatory| Description                                                        |
77| ------ | ------- | ---- | ------------------------------------------------------------ |
78| value  | boolean | Yes  | Whether to set the component as the default focus of the parent container. This parameter takes effect only when the container is new and obtains focus for the first time.<br>Default value: **false**<br>**NOTE**<br>This parameter must be used together with [tabIndex](#tabindex9). When **tabIndex** is set for a container and **groupDefaultFocus(true)** is set for a child in the container or for the container itself, then when the container obtains focus for the first time through sequential Tab navigation, the focus automatically moves to the specified component. If **groupDefaultFocus(true)** is set for multiple components in the container (including the container itself), the first component found in the component tree in-depth traversal receives the focus.|
79
80## focusOnTouch<sup>9+</sup>
81
82focusOnTouch(value: boolean)
83
84Sets whether the component is focusable on touch.
85
86**Atomic service API**: This API can be used in atomic services since API version 11.
87
88**System capability**: SystemCapability.ArkUI.ArkUI.Full
89
90**Parameters**
91
92| Name| Type   | Mandatory| Description                                                        |
93| ------ | ------- | ---- | ------------------------------------------------------------ |
94| value  | boolean | Yes  | Whether the component is focusable on touch.<br>Default value: **false**<br>**NOTE**<br>The component is focusable only when it is touchable.|
95
96## focusBox<sup>12+</sup>
97
98focusBox(style: FocusBoxStyle): T
99
100Sets the system focus box style for the component.
101
102**Atomic service API**: This API can be used in atomic services since API version 12.
103
104**System capability**: SystemCapability.ArkUI.ArkUI.Full
105
106**Parameters**
107
108| Name| Type| Mandatory| Description|
109| ---- | ---- | ---- | ---- |
110| style  | [FocusBoxStyle](#focusboxstyle12) | Yes  | System focus box style for the component.<br>**NOTE**<br>This style affects only the components that display the system focus box during focus traversal.|
111
112
113## focusControl<sup>9+</sup>
114
115Implements focus control.
116
117**Atomic service API**: This API can be used in atomic services since API version 11.
118
119### requestFocus<sup>9+</sup>
120
121requestFocus(value: string): boolean
122
123Requests the focus to move to the specified component. It is a global API. This API does not take effect in the current frame; the focus change will occur in the next frame. Use the [requestFocus](../js-apis-arkui-UIContext.md#requestfocus12) API in **FocusController** for immediate effect.
124
125**Atomic service API**: This API can be used in atomic services since API version 11.
126
127**Parameters**
128
129| Name| Type| Mandatory| Description|
130| ----- | ------ | ---- | ---- |
131| value | string | Yes  | String bound to the target component using **key(value: string)** or **id(value: string)**.|
132
133**Return value**
134
135| Type| Description|
136| ------- | ---- |
137| boolean | Returns whether the focus is successfully moved to the target component. Returns **true** if the specified component exists and the focus is successfully moved to the target component; returns **false** otherwise.|
138
139>  **NOTE**
140>
141>  The following components support focus control: [TextInput](ts-basic-components-textinput.md), [TextArea](ts-basic-components-textarea.md), [Search](ts-basic-components-search.md), [Button](ts-basic-components-button.md), [Text](ts-basic-components-text.md), [Image](ts-basic-components-image.md), [List](ts-container-list.md), [Grid](ts-container-grid.md). Currently, the running effect of the focus event can be displayed only on a real device.
142
143## FocusBoxStyle<sup>12+</sup>
144
145**Atomic service API**: This API can be used in atomic services since API version 12.
146
147| Name| Type| Mandatory| Description|
148| ---- | ---- | ---- | ---- |
149| margin  | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | No| Distance of the focus box from the component's edge.<br>A positive number indicates the outside, and a negative number indicates the inside. The value cannot be in percentage.|
150| strokeColor  | [ColorMetrics](../js-apis-arkui-graphics.md#colormetrics12) | No| Stroke color of the focus box.|
151| strokeWidth | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | No| Stroke width of the focus box.<br>Negative numbers and percentages are not supported.|
152
153## focusScopePriority<sup>12+</sup>
154
155focusScopePriority(scopeId: string, priority?: FocusPriority): T
156
157Sets the focus priority of this component in a specified container. It must be used together with **focusScopeId**.
158
159**Atomic service API**: This API can be used in atomic services since API version 12.
160
161**System capability**: SystemCapability.ArkUI.ArkUI.Full
162
163**Parameters**
164
165| Name| Type   | Mandatory| Description                                                        |
166| ------ | ------- | ---- | ------------------------------------------------------------ |
167| scopeId  | string | Yes  | ID of the container component where the current component's focus priority takes effect.<br>**NOTE**<br>1. The current component must be within the container identified by **scopeId**, or the container to which the current component belongs must be within the container identified by **scopeId**.<br>2. A component cannot set multiple priorities.<br>3. A container component with **focusScopeId** set cannot have its priority set.|
168| priority  | [FocusPriority](#focuspriority12)  | No  | Focus priority.<br>**NOTE**<br>If **priority** is not set, the component uses the default **AUTO** priority.<br>Impact of the priority on focus traversal and component focus:<br>1. When the container gains focus as a whole (page level switching/focus switching to a focus group/container component requesting focus with **requestFocus**), if there is a component with a priority of **PREVIOUS** within the container, that component gains focus; otherwise, the last focused component does.<br>2. When a container does not gain focus as a whole (using **Tab** or arrow keys in non-focus group scenarios), the highest priority component gets focus on first focus; subsequent focus follows position order regardless of priority.|
169
170### FocusPriority<sup>12+</sup>
171
172**Atomic service API**: This API can be used in atomic services since API version 12.
173
174**System capability**: SystemCapability.ArkUI.ArkUI.Full
175
176| Name         | Description       |
177| ----------- | --------- |
178| AUTO | Default priority, that is, the focus priority assigned by default.|
179| PRIOR | Priority that indicates the component is prioritized in the container. This level is higher than **AUTO**.|
180| PREVIOUS | Priority of a previously focused node in the container. This level is higher than **PRIOR**.|
181
182## focusScopeId<sup>12+</sup>
183
184focusScopeId(id: string, isGroup?: boolean)
185
186Assigns an ID to this container component and specifies whether the container is a focus group.
187
188**Atomic service API**: This API can be used in atomic services since API version 12.
189
190**System capability**: SystemCapability.ArkUI.ArkUI.Full
191
192**Parameters**
193
194| Name| Type   | Mandatory| Description                                                        |
195| ------ | ------- | ---- | ------------------------------------------------------------ |
196| id  | string | Yes  | ID of the current container component.<br>**NOTE**<br>The ID must be unique within a single level page.|
197| isGroup  | boolean | No  | Whether the current container component is a focus group.<br>**NOTE**<br>Focus groups cannot be nested and should not be configured repeatedly.<br> The focus group and **tabIndex** cannot be used together.<br>The focus group enables the container and its elements to navigate focus according to the focus group rules as follows:<br>1. Only arrow keys are allowed for focus traversal within the focus group; the **Tab** key will move the focus out of the focus group.<br>2. When arrow keys are used to move the focus from outside the focus group to inside, if there is a component with a priority of **PREVIOUS** within the focus group, that component gains focus; otherwise, the last focused component does.|
198
199## focusScopeId<sup>14+</sup>
200
201focusScopeId(id: string, isGroup?: boolean, arrowStepOut?: boolean)
202
203Assigns an ID to this container component and specifies whether the container is a focus group.
204
205**System capability**: SystemCapability.ArkUI.ArkUI.Full
206
207**Parameters**
208
209| Name| Type   | Mandatory| Description                                                        |
210| ------ | ------- | ---- | ------------------------------------------------------------ |
211| id  | string | Yes  | ID of the current container component.<br>**NOTE**<br>The ID must be unique within a single level page.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
212| isGroup  | boolean | No  | Whether the current container component is a focus group.<br>**NOTE**<br>Focus groups cannot be nested and should not be configured repeatedly.<br> The focus group and **tabIndex** cannot be used together.<br>The focus group enables the container and its elements to navigate focus according to the focus group rules as follows:<br>1. Only arrow keys are allowed for focus traversal within the focus group; the **Tab** key will move the focus out of the focus group.<br>2. When arrow keys are used to move the focus from outside the focus group to inside, if there is a component with a priority of **PREVIOUS** within the focus group, that component gains focus; otherwise, the last focused component does.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
213| arrowStepOut<sup>14+</sup>  | boolean | No  | Whether the focus can be moved out of the current focus group using arrow keys.<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
214
215## tabStop<sup>14+</sup>
216
217tabStop(isTabStop: boolean) :T
218
219Sets whether this container component is a focus stop. During focus traversal, the focus stops at the container component serving as a focus stop.
220
221**Atomic service API**: This API can be used in atomic services since API version 14.
222
223**System capability**: SystemCapability.ArkUI.ArkUI.Full
224
225**Parameters**
226
227| Name| Type   | Mandatory| Description                                                        |
228| ------ | ------- | ---- | ------------------------------------------------------------ |
229| isTabStop  | boolean | Yes  | Whether the current container component is a focus stop.<br>**NOTE**<br>1. To configure **tabStop**, make sure the component is a container and has focusable child components. By default, container components cannot directly gain focus.<br> 2. When [requestFocus](../js-apis-arkui-UIContext.md#requestfocus12) is used for requesting focus, if the component is a container and **tabStop** is configured, the focus can stop at the container. If **tabStop** is not configured, the component can still gain focus, even if there are other components in the focus chain with **tabStop** configured.<br>3. Containers with **tabStop** configured should not be nested more than two levels deep.<br>Focus traversal rules with **tabStop**:<br>1. During focus traversal using the **Tab** key or arrow keys, the focus stops at components with **tabStop** configured. If the focus is inside a container with **tabStop** configured, it can move to the next focusable component within the container. If the focus is outside such a container, it can move to the next focusable component outside the container.<br>2. When the focus is on a container with **tabStop** configured, pressing **Enter** will move the focus to the first focusable component inside the container. Pressing **ESC** will move the focus back to the previous component with **tabStop** configured, not exceeding the current level of the page root container. Pressing the spacebar will trigger the **onClick** event of the container.<br>3. Whenever possible, avoid configuring **tabStop** on the root container. If **tabStop** is configured on the root container, the following behaviors will occur:<br>- Using [clearFocus](../js-apis-arkui-UIContext.md#clearfocus12) to clear the focus to the root container and then pressing **Enter** will return to the previously focused component inside the root container.<br>Using **ESC** to clear the focus to the root container and then pressing **Enter** will move the focus to the first focusable component inside the root container.|
230
231**Example for describing the keys and focusable components during focus traversal**
232
233![tabStop](figures/tabStop.png)
234
235If the current focus is on **button2**, pressing the **Tab** key will move the focus to **Column3**. Pressing the **Tab** key again will move the focus back to **button1**.
236
237## Example
238
239### Example 1: Setting Focus and Focus Traversal Effects for Components
240
241This example shows how to use **defaultFocus**, **groupDefaultFocus**, and **focusOnTouch**. **defaultFocus** sets the bound component as the initial focus after the page is created. **groupDefaultFocus** sets the bound component as the initial focus after the container with the specified **tabIndex** is created. **focusOnTouch** sets the bound component to obtain focus upon being clicked.
242
243```ts
244// focusTest.ets
245@Entry
246@Component
247struct FocusableExample {
248  @State inputValue: string = ''
249
250  build() {
251    Scroll() {
252      Row({ space: 20 }) {
253        Column({ space: 20 }) {
254          Column({ space: 5 }) {
255            Button('Group1')
256              .width(165)
257              .height(40)
258              .fontColor(Color.White)
259              .focusOnTouch(true)           // The button is focusable on touch.
260            Row({ space: 5 }) {
261              Button()
262                .width(80)
263                .height(40)
264                .fontColor(Color.White)
265              Button()
266                .width(80)
267                .height(40)
268                .fontColor(Color.White)
269                .focusOnTouch(true)           // The button is focusable on touch.
270            }
271            Row({ space: 5 }) {
272              Button()
273                .width(80)
274                .height(40)
275                .fontColor(Color.White)
276              Button()
277                .width(80)
278                .height(40)
279                .fontColor(Color.White)
280            }
281          }.borderWidth(2).borderColor(Color.Red).borderStyle(BorderStyle.Dashed)
282          .tabIndex(1)                      // The column is the initial component to have focus in sequential keyboard navigation.
283          Column({ space: 5 }) {
284            Button('Group2')
285              .width(165)
286              .height(40)
287              .fontColor(Color.White)
288            Row({ space: 5 }) {
289              Button()
290                .width(80)
291                .height(40)
292                .fontColor(Color.White)
293              Button()
294                .width(80)
295                .height(40)
296                .fontColor(Color.White)
297                .groupDefaultFocus(true)      // The button obtains focus when its upper-level column is in focus.
298            }
299            Row({ space: 5 }) {
300              Button()
301                .width(80)
302                .height(40)
303                .fontColor(Color.White)
304              Button()
305                .width(80)
306                .height(40)
307                .fontColor(Color.White)
308            }
309          }.borderWidth(2).borderColor(Color.Green).borderStyle(BorderStyle.Dashed)
310          .tabIndex(2)                      // The column is the second component to have focus in sequential keyboard navigation.
311        }
312        Column({ space: 5 }) {
313          TextInput({placeholder: 'input', text: this.inputValue})
314            .onChange((value: string) => {
315              this.inputValue = value
316            })
317            .width(156)
318            .defaultFocus(true)             // The <TextInput> component is the initial default focus of the page.
319          Button('Group3')
320            .width(165)
321            .height(40)
322            .fontColor(Color.White)
323          Row({ space: 5 }) {
324            Button()
325              .width(80)
326              .height(40)
327              .fontColor(Color.White)
328            Button()
329              .width(80)
330              .height(40)
331              .fontColor(Color.White)
332          }
333          Button()
334            .width(165)
335            .height(40)
336            .fontColor(Color.White)
337          Row({ space: 5 }) {
338            Button()
339              .width(80)
340              .height(40)
341              .fontColor(Color.White)
342            Button()
343              .width(80)
344              .height(40)
345              .fontColor(Color.White)
346          }
347          Button()
348            .width(165)
349            .height(40)
350            .fontColor(Color.White)
351          Row({ space: 5 }) {
352            Button()
353              .width(80)
354              .height(40)
355              .fontColor(Color.White)
356            Button()
357              .width(80)
358              .height(40)
359              .fontColor(Color.White)
360          }
361        }.borderWidth(2).borderColor(Color.Orange).borderStyle(BorderStyle.Dashed)
362        .tabIndex(3)                      // The column is the third component to have focus in sequential keyboard navigation.
363      }.alignItems(VerticalAlign.Top)
364    }
365  }
366}
367```
368Diagrams:
369
370On first-time access, the focus is on the **TextInput** component bound to **defaultFocus**.
371
372![defaultFocus](figures/defaultFocus.png)
373
374When you press the **Tab** key for the first time, the focus switches to the container that matches **tabIndex(1)** and automatically moves to the component bound to **groupDefaultFocus**.
375
376![groupDefaultFocus1](figures/groupDefaultFocus1.png)
377
378When you press the **Tab** key for the second time, the focus switches to the container that matches **tabIndex(2)** and automatically moves to the component bound to **groupDefaultFocus**.
379
380![groupDefaultFocus2](figures/groupDefaultFocus2.png)
381
382When you press the **Tab** key for the third time, the focus switches to the container that matches **tabIndex(3)** and automatically moves to the component bound to **groupDefaultFocus**.
383
384![groupDefaultFocus3](figures/groupDefaultFocus3.png)
385
386Clicking the component bound to **focusOnTouch** sets the focus on the component and removes the focus indicator. Pressing the Tab key again displays the focus indicator.
387
388![focusOnTouch](figures/focusOnTouch.png)
389
390### Example 2: Setting Focus on a Specific Component
391
392This example demonstrates how to set focus on a specific component using **focusControl.requestFocus**.
393
394> **NOTE**
395>
396> To avoid confusion with **focusControl** instances, it is recommended that you obtain a **UIContext** instance using the [getUIContext](../js-apis-arkui-UIContext.md#uicontext) API, and then obtain the **focusControl** instance bound to the context through the [getFocusController](../js-apis-arkui-UIContext.md#getfocuscontroller12) API.
397
398```ts
399// requestFocus.ets
400@Entry
401@Component
402struct RequestFocusExample {
403  @State idList: string[] = ['A', 'B', 'C', 'D', 'E', 'F', 'LastPageId']
404  @State selectId: string = 'LastPageId'
405
406  build() {
407    Column({ space:20 }){
408      Row({space: 5}) {
409        Button("id: " + this.idList[0] + " focusable(false)")
410          .width(200).height(70).fontColor(Color.White)
411          .id(this.idList[0])
412          .focusable(false)
413        Button("id: " + this.idList[1])
414          .width(200).height(70).fontColor(Color.White)
415          .id(this.idList[1])
416      }
417      Row({space: 5}) {
418        Button("id: " + this.idList[2])
419          .width(200).height(70).fontColor(Color.White)
420          .id(this.idList[2])
421        Button("id: " + this.idList[3])
422          .width(200).height(70).fontColor(Color.White)
423          .id(this.idList[3])
424      }
425      Row({space: 5}) {
426        Button("id: " + this.idList[4])
427          .width(200).height(70).fontColor(Color.White)
428          .id(this.idList[4])
429        Button("id: " + this.idList[5])
430          .width(200).height(70).fontColor(Color.White)
431          .id(this.idList[5])
432      }
433      Row({space: 5}) {
434        Select([{value: this.idList[0]},
435                {value: this.idList[1]},
436                {value: this.idList[2]},
437                {value: this.idList[3]},
438                {value: this.idList[4]},
439                {value: this.idList[5]},
440                {value: this.idList[6]}])
441          .value(this.selectId)
442          .onSelect((index: number) => {
443            this.selectId = this.idList[index]
444          })
445        Button("RequestFocus")
446          .width(200).height(70).fontColor(Color.White)
447          .onClick(() => {
448            // You are advised to use this.getUIContext().getFocusController().requestFocus().
449            let res = focusControl.requestFocus(this.selectId)      // Move the focus to the component specified by this.selectId.
450            if (res) {
451              this.getUIContext().getPromptAction().showToast({message: 'Request success'})
452            } else {
453              this.getUIContext().getPromptAction().showToast({message: 'Request failed'})
454            }
455          })
456      }
457    }.width('100%').margin({ top:20 })
458  }
459}
460```
461
462Diagrams:
463
464Press the **Tab** key to activate the focus state.
465Below shows how the UI behaves when you request focus for a component that does not exist.
466
467![requestFocus1](figures/requestFocus1.png)
468
469Below shows how the UI behaves when you request focus for a component that is not focusable.
470
471![requestFocus2](figures/requestFocus2.png)
472
473Below shows how the UI behaves when you request focus for a focusable component.
474
475![requestFocus3](figures/requestFocus3.png)
476
477### Example 3: Customizing the Focus Box Style
478
479This example shows how to change the focus box style of a component by configuring **focusBox**.
480
481```ts
482import { ColorMetrics, LengthMetrics } from '@kit.ArkUI'
483
484@Entry
485@Component
486struct RequestFocusExample {
487  build() {
488    Column({ space: 30 }) {
489      Button("small black focus box")
490        .focusBox({
491          margin: new LengthMetrics(0),
492          strokeColor: ColorMetrics.rgba(0, 0, 0),
493        })
494      Button("large red focus box")
495        .focusBox({
496          margin: LengthMetrics.px(20),
497          strokeColor: ColorMetrics.rgba(255, 0, 0),
498          strokeWidth: LengthMetrics.px(10)
499        })
500    }
501    .alignItems(HorizontalAlign.Center)
502    .width('100%')
503  }
504}
505```
506
507![focusBox](figures/focusBox.gif)
508
509
510### Example 4: Setting Focus Group Traversal
511
512This example demonstrates how to set a component as the initial focus when its container gains focus by configuring **focusScopePriority**. Configuring **focusScopeId** allows the bound container component to become a focus group.
513
514```ts
515// focusTest.ets
516@Entry
517@Component
518struct FocusableExample {
519  @State inputValue: string = ''
520
521  build() {
522    Scroll() {
523      Row({ space: 20 }) {
524        Column({ space: 20 }) {  // Labeled as Column1.
525          Column({ space: 5 }) {
526            Button('Group1')
527              .width(165)
528              .height(40)
529              .fontColor(Color.White)
530            Row({ space: 5 }) {
531              Button()
532                .width(80)
533                .height(40)
534                .fontColor(Color.White)
535              Button()
536                .width(80)
537                .height(40)
538                .fontColor(Color.White)
539            }
540            Row({ space: 5 }) {
541              Button()
542                .width(80)
543                .height(40)
544                .fontColor(Color.White)
545              Button()
546                .width(80)
547                .height(40)
548                .fontColor(Color.White)
549            }
550          }.borderWidth(2).borderColor(Color.Red).borderStyle(BorderStyle.Dashed)
551          Column({ space: 5 }) {
552            Button('Group2')
553              .width(165)
554              .height(40)
555              .fontColor(Color.White)
556            Row({ space: 5 }) {
557              Button()
558                .width(80)
559                .height(40)
560                .fontColor(Color.White)
561              Button()
562                .width(80)
563                .height(40)
564                .fontColor(Color.White)
565                .focusScopePriority('ColumnScope1', FocusPriority.PRIOR) // Focuses when Column1 first gains focus.
566            }
567            Row({ space: 5 }) {
568              Button()
569                .width(80)
570                .height(40)
571                .fontColor(Color.White)
572              Button()
573                .width(80)
574                .height(40)
575                .fontColor(Color.White)
576            }
577          }.borderWidth(2).borderColor(Color.Green).borderStyle(BorderStyle.Dashed)
578        }
579        .focusScopeId('ColumnScope1')
580        Column({ space: 5 }) {  // Labeled as Column2.
581          TextInput({placeholder: 'input', text: this.inputValue})
582            .onChange((value: string) => {
583              this.inputValue = value
584            })
585            .width(156)
586          Button('Group3')
587            .width(165)
588            .height(40)
589            .fontColor(Color.White)
590          Row({ space: 5 }) {
591            Button()
592              .width(80)
593              .height(40)
594              .fontColor(Color.White)
595            Button()
596              .width(80)
597              .height(40)
598              .fontColor(Color.White)
599          }
600          Button()
601            .width(165)
602            .height(40)
603            .fontColor(Color.White)
604            .focusScopePriority('ColumnScope2', FocusPriority.PREVIOUS)  // Focuses when Column2 first gains focus.
605          Row({ space: 5 }) {
606            Button()
607              .width(80)
608              .height(40)
609              .fontColor(Color.White)
610            Button()
611              .width(80)
612              .height(40)
613              .fontColor(Color.White)
614          }
615          Button()
616            .width(165)
617            .height(40)
618            .fontColor(Color.White)
619          Row({ space: 5 }) {
620            Button()
621              .width(80)
622              .height(40)
623              .fontColor(Color.White)
624            Button()
625              .width(80)
626              .height(40)
627              .fontColor(Color.White)
628          }
629        }.borderWidth(2).borderColor(Color.Orange).borderStyle(BorderStyle.Dashed)
630        .focusScopeId('ColumnScope2', true) // Column2 is a focus group.
631      }.alignItems(VerticalAlign.Top)
632    }
633  }
634}
635```
636
637### Example 5: Setting Focus Stop
638
639This example illustrates how to use **tabStop** to make the focus stop on a component during focus traversal with the **Tab** key.
640
641```ts
642import { ColorMetrics, LengthMetrics } from '@kit.ArkUI'
643
644@Entry
645@Component
646struct TabStop {
647  build() {
648    Column({ space: 20 }) {
649      Column({ space: 20 }) {
650        Column({ space: 20 }) {
651          Row({ space: 5 }) {
652            Button("button 1")
653              .width(200).height(70).fontColor(Color.White)
654              .focusBox({
655                margin: LengthMetrics.px(20),
656                strokeColor: ColorMetrics.rgba(255, 0, 0),
657                strokeWidth: LengthMetrics.px(10)
658              })
659          }
660          Row({ space: 5 }) {
661            Button("button 2")
662              .width(200).height(70).fontColor(Color.White)
663              .focusBox({
664                margin: LengthMetrics.px(20),
665                strokeColor: ColorMetrics.rgba(255, 0, 0),
666                strokeWidth: LengthMetrics.px(10)
667              })
668          }
669        }.width('80%').margin({ top: 30 }).borderColor(Color.Black)
670      }.width('95%').margin({ top: 60 }).borderColor(Color.Black)
671      Column({ space: 20 }) {
672        Column({ space: 20 }) {
673          Row({ space: 5 }) {
674            Button("button 3")
675              .width(200)
676              .height('70%')
677              .fontColor(Color.White)
678              .focusBox({
679                margin: LengthMetrics.px(20),
680                strokeColor: ColorMetrics.rgba(255, 0, 0),
681                strokeWidth: LengthMetrics.px(10)
682              })
683              .margin({ top: 15 })
684          }
685        }
686        .width('80%')
687        .height('120')
688        .borderColor(Color.Black)
689        .margin({ top: 10 })
690        .tabStop(true)
691        .focusBox({
692          margin: LengthMetrics.px(20),
693          strokeColor: ColorMetrics.rgba(255, 0, 0),
694          strokeWidth: LengthMetrics.px(10)
695        })
696        .borderWidth(1)
697      }.width('95%').margin({ top: 50 }).borderColor(Color.Black)
698    }
699  }
700}
701```
702Diagrams:
703
704When the **Tab** key is pressed twice in succession, the focus is on the second child component.
705
706![tabStop1](figures/tabStop1.png)
707
708After the **Tab** key is pressed again, the focus moves to the component configured with **tabStop**.
709
710![tabStop2](figures/tabStop2.png)
711
712After the **Tab** key is pressed once more, the focus loops back to the first child component.
713
714![tabStop3](figures/tabStop3.png)
715