1# Focus Event 2 3## Basic Concepts and Specifications 4 5### Basic Concepts 6 7**Focus, Focus Chain, and Focus Traversal** 8 9- Focus: refers to the single interactive element on the current application screen. When users interact indirectly with the application using non-pointing input devices such as keyboards, TV remote controls, or in-car joysticks/knobs, navigation and interaction based on focus are crucial means of input. 10- Focus chain: refers to the sequence of nodes from the root to a focused component in the application's component tree, where all nodes are considered focused. 11- Focus traversal: refers to the behavior of focus shifting between components in an application. This process is transparent to the user but can be monitored through **onFocus** and **onBlur** events. For details on how focus traversal is managed, see [Focus Traversal Guidelines](#focus-traversal-guidelines) 12 13 14**Focus State** 15 16Refers to the style indicating the currently focused component. 17 18- Display rules: The focus state is not displayed by default; it only appears when the application is active. A component with the focus state is definitely focused, but not all focused components show the state, depending on the activation status. Most components come with default focus state styles; you customize these styles when needed. Once customized, the component will no longer display the default focus state style. For details about how to set the focus state style, see [Focus Style](#focus-style). In a focus chain, if multiple components have the focus state, the system shows the focus state for only one, prioritizing the child component's focus state over others. 19- Entering the activation state: Pressing the **Tab** key on an external keyboard or using the **activate(true)** API of **FocusController** activates focus, allowing subsequent use of the **Tab** key or arrow keys for focus traversal. The initial **Tab** press that activates focus does not cause focus to move. 20- Exiting the activation state: Focus activation ends when the application receives either the **activate(true)** API call from **FocusController** or any form of click event, such as touchscreen presses or mouse clicks. 21 22```ts 23@Entry 24@Component 25struct FocusActiveExample { 26 build() { 27 Column() { 28 Button('Set Active').width(140).height(45).margin(5).onClick(() => { 29 this.getUIContext().getFocusController().activate(true, true); 30 }) 31 Button('Set Not Active').width(140).height(45).margin(5).onClick(() => { 32 this.getUIContext().getFocusController().activate(false, true); 33 }) 34 }.width('100%') 35 } 36} 37``` 38 39 40When the **Tab** key is pressed, the focus state is activated. Clicking the mouse button exits the focus state. 41 42 43 44 45The [activate](../reference/apis-arkui/js-apis-arkui-UIContext.md#activate14) API is used to enter and exit the focus activation state. 46 47 48 49Example steps: 501. Click **Set Active** and call the [activate](../reference/apis-arkui/js-apis-arkui-UIContext.md#activate14) API to enter the focus activation state. 512. Use the **Tab** key to move the focus to the **Set Not Active** button, and then press the **Enter** key to trigger the key event and call the [activate](../reference/apis-arkui/js-apis-arkui-UIContext.md#activate14) API to exit the focus activation state. 52 53**Hierarchical Pages** 54 55Hierarchical pages are specialized container components, such as **Page**, **Dialog**, **SheetPage**, **ModalPage**, **Menu**, **Popup**, **NavBar**, and **NavDestination**, within a focus framework. These components typically have the following key features: 56 57- Visual layering: They appear on top of other content, creating a distinct visual hierarchy. 58- Focus capture: They automatically take focus when first displayed. 59- Focus limitation: When focus is within these components, users cannot use keyboard keys to move focus outside to other elements. In other words, focus movement is confined within the component. 60 61An application always has at least one hierarchical page in focus. When this hierarchical page is closed or no longer visible, the focus shifts to another, ensuring smooth user interaction. 62 63> **NOTE** 64> 65> The **Popup** component does not capture focus if it has **focusable** set to **false**. 66> 67> The **NavBar** and **NavDestination** components do not restrict focus movement and share the focus scope of their immediate parent hierarchical page. 68 69**Root Container** 70 71In hierarchical pages, the root container is where the default focus resides when the page is first shown. 72 73You can change the default focus using the **defaultFocus** attribute. 74 75Pressing **Tab** with focus on the root container activates focus and passes it to child components. Focus proceeds to the last focused child or the first child if no previous focus exists, until it reaches the leaf node. 76 77### Focus Traversal Guidelines 78 79Focus traversal can be divided into active and passive based on how it is triggered. 80 81**Active Focus Traversal** 82 83 84Active focus traversal refers to focus movement initiated by deliberate actions, such as keyboard shortcuts (**Tab**, **Shift+Tab**, arrow keys) and programmatic focus control through **requestFocus**, **clearFocus**, and **focusOnTouch**. 85 86 87- Keyboard traversal 881. Prerequisite: The application is in the focus activation state. 892. Scope: limited to the currently focused hierarchical page, as detailed in the "Focus limitation" section under "Hierarchical Pages." 903. Key types: 91**Tab** key: follows a Z-shaped logic to traverse all leaf nodes within the scope, looping back to the first after the last. 92**Shift+Tab**: reverses the direction of the **Tab** key. 93Arrow keys (up, down, left, and right): moves focus in a cross-shaped pattern, with container-specific algorithms determining the next focus in a single-layer container. If the algorithm determines the next focus should be on a container component, the system uses a center-point distance priority algorithm to further identify the target child node within the container. 944. Traversal algorithm: Each focusable container has a unique algorithm defining how focus moves. 955. Priority: Child components take precedence in handling keyboard events over parents. 96 97- requestFocus 98Moves focus to a specific component, which is allowed across hierarchical pages but not across windows or different ArkUI instances. 99For details, see [Active Focus Acquisition/Loss](#active-focus-acquisitionloss). 100 101- clearFocus 102Clears the focus within the current hierarchical page, with the focus reverting to the root container. For details, see [clearFocus](../reference/apis-arkui/js-apis-arkui-UIContext.md#clearfocus12). 103 104- focusOnTouch 105Enables a component to gain focus on touch. It is ineffective on non-focusable components. For container components, focus goes to the last focused child or the first focusable child upon touch. For details, see [focusOnTouch](../reference/apis-arkui/arkui-ts/ts-universal-attributes-focus.md#focusontouch9). 106 107 108**Passive Focus Traversal** 109 110Passive focus traversal occurs when the focus automatically shifts due to system actions or other operations without developer intervention, reflecting the default behavior of the focus system. 111 112 113Mechanisms that trigger passive focus traversal include: 114 115- Component removal: If a focused component is removed, the system tries to shift focus to the next available sibling, following a back-to-front order. If no siblings are focusable, focus is released to the parent component. 116- Attribute change: Changing a component's **focusable** or **enabled** to **false**, or **visibility** to invisible causes the system to automatically move focus to another focusable component, using the same method as for component removal. 117- Hierarchical page transition: During switching between hierarchical pages, the current page's focus is automatically released, and the new page may automatically gain focus according to preset logic. 118- **Web** component initialization: The **Web** component may immediately gain focus upon creation if designed to do so (for example, certain dialog boxes or text boxes), which is part of the component's behavior and not governed by the focus framework specifications. 119 120### Focus Traversal Algorithms 121 122In the focus management system, every focusable container is assigned a specific algorithm that dictates how focus moves from the current to the next focusable child component when **Tab**, **Shift+Tab**, or arrow keys are used. 123 124The algorithm used by a container is based on its UX design and is implemented by the component itself. The focus framework supports three focus traversal algorithms: linear, projection, and custom. 125 126**Linear Focus Traversal Algorithm** 127 128 129The linear focus traversal algorithm is the default algorithm, focusing on the order of child nodes in the node tree, commonly used in single-direction layouts such as **Row**, **Column**, and **Flex** containers. Its operation rules are as follows: 130 131 132- Order dependency: The focus order is based solely on the mounting sequence of child nodes in the node tree, independent of their visual layout. 133- **Tab** key focus traversal: The **Tab** key moves focus through focusable elements in the order they are mounted in the component tree. 134- Arrow key focus traversal: Arrow keys perpendicular to the container's layout direction are ignored. For example, a horizontal **Row** container does not accept focus requests from up and down keys. 135- Boundary handling: The container rejects focus requests in the opposite direction from the current focus edge. For example, if the focus is on the first child of a horizontal **Row** container, it won't process leftward focus requests. 136 137```ts 138@Entry 139@Component 140struct FocusLinerExample { 141 build() { 142 Column() { 143 Column() { 144 Button("Column Button1") 145 .width(150) 146 .height(45) 147 .fontColor(Color.White) 148 .margin(10) 149 Button("Column Button2") 150 .width(150) 151 .height(45) 152 .fontColor(Color.White) 153 .margin(10) 154 } 155 .margin(10) 156 157 Row() { 158 Button("Row Button1") 159 .width(150) 160 .height(45) 161 .fontColor(Color.White) 162 .margin(10) 163 Button("Row Button2") 164 .width(150) 165 .height(45) 166 .fontColor(Color.White) 167 .margin(10) 168 } 169 } 170 } 171} 172``` 173 174Pressing the **Tab** key moves focus through focusable elements in the order they are mounted in the component tree. 175 176 177 178In a vertical **Column** container, you can use the up and down arrow keys to navigate between focusable elements. The left and right arrow keys are not applicable. 179 180 181 182In a horizontal **Row** container, use the left and right arrow keys to navigate between focusable elements. The up and down arrow keys are not applicable. 183 184 185 186 187**Projection-based Focus Traversal Algorithm** 188 189The projection-based focus traversal algorithm determines the next focus based on the overlap area and center-point distance of the projection of the current focused component in the direction of focus movement. It is particularly suitable for containers with varying child sizes, such as the **Flex** component with the **wrap** attribute. Its operation rules are as follows: 190 191 192- Arrow keys: Focus goes to the child with the largest overlap area and the shortest center-point distance to the projection of the current focus. If multiple children qualify, the first in the node tree is chosen. If no components overlap with the projection, the focus request is unprocessable. 193- **Tab** key: It mimics a rightward shift to find the next focus; if none is available, it simulates moving the current focus down its height, and then checks leftward. The child farthest in the direction with overlapping projection wins. 194- **Shift+Tab** key: It mimics a leftward shift to find the next focus; if none is available, it simulates moving the current focus up its height, and then checks rightward. The child farthest in the direction with overlapping projection wins. 195 196```ts 197@Entry 198@Component 199struct ProjectAreaFocusExample { 200 build() { 201 Column() { 202 Column({ space: 5 }) { 203 Text('Wrap').fontSize(12).width('90%') 204 // Multi-line layout for child components 205 Flex({ wrap: FlexWrap.Wrap }) { 206 Button('1').width(140).height(50).margin(5) 207 Button('2').width(140).height(50).margin(5) 208 Button('3').width(140).height(50).margin(5) 209 Button('4').width(140).height(50).margin(5) 210 Button('5').width(140).height(50).margin(5) 211 } 212 .width('90%') 213 .padding(10) 214 }.width('100%').margin({ top: 5 }) 215 }.width('100%') 216 } 217} 218``` 219 220> **NOTE** 221> 222> - The focus order calculated by the projection-based focusing algorithm is closely related to the component layout and size. It is recommended for use in scenarios where components are arranged in a regular and uniform manner. If components have varying sizes and overlap horizontally or vertically, the resulting focus order may deviate from the expected sequence. 223> - If a clear focus order is required, it is recommended that you use containers that support sequential focusing, such as **Column** or **Row**. 224 225When the components in a **Flex** multi-line layout have uniform sizes, the focus traversal works as expected. 226 227 228 229```ts 230@Entry 231@Component 232struct ProjectAreaFocusExample2 { 233 build() { 234 Column() { 235 Column({ space: 5 }) { 236 Text('Wrap').fontSize(12).width('90%') 237 // Multi-line layout for child components 238 Flex({ wrap: FlexWrap.Wrap }) { 239 Button('1').width(145).height(50).margin(5) 240 Button('2').width(145).height(50).margin(5) 241 Button('3').width(150).height(50).margin(5) 242 Button('4').width(160).height(50).margin(5) 243 Button('5').width(170).height(50).margin(5) 244 } 245 .width('90%') 246 .padding(10) 247 }.width('100%').margin({ top: 5 }) 248 }.width('100%') 249 } 250} 251``` 252 253When components in a **Flex** multi-line layout have varying sizes and overlap vertically, the **Tab** key focus traversal fails to reach the buttons labeled **3**, **4**, and **5** in the lower row. 254 255 256 257 258**Custom Focus Traversal Algorithm** 259 260The custom focus traversal algorithm is defined by the component itself, allowing for specific focus traversal behaviors as determined by the component's design specifications. 261 262## onFocus/onBlur Events 263 264```ts 265onFocus(event: () => void) 266``` 267 268 269Triggered when the bound component obtains focus. 270 271```ts 272onBlur(event:() => void) 273``` 274 275Triggered when the bound component loses focus. 276 277The **onFocus** and **onBlur** APIs are usually used in pairs to listen for the focus changes of the component. 278 279```ts 280// xxx.ets 281@Entry 282@Component 283struct FocusEventExample { 284 @State oneButtonColor: Color = Color.Gray; 285 @State twoButtonColor: Color = Color.Gray; 286 @State threeButtonColor: Color = Color.Gray; 287 288 build() { 289 Column({ space: 20 }) { 290 // 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. 291 Button('First Button') 292 .width(260) 293 .height(70) 294 .backgroundColor(this.oneButtonColor) 295 .fontColor(Color.Black) 296 // Listen for the focus obtaining event of the first component and change its color when it obtains focus. 297 .onFocus(() => { 298 this.oneButtonColor = Color.Green; 299 }) 300 // Listen for the focus loss event of the first component and change its color when it loses focus. 301 .onBlur(() => { 302 this.oneButtonColor = Color.Gray; 303 }) 304 305 Button('Second Button') 306 .width(260) 307 .height(70) 308 .backgroundColor(this.twoButtonColor) 309 .fontColor(Color.Black) 310 // Listen for the focus obtaining event of the second component and change its color when it obtains focus. 311 .onFocus(() => { 312 this.twoButtonColor = Color.Green; 313 }) 314 // Listen for the focus loss event of the second component and change its color when it loses focus. 315 .onBlur(() => { 316 this.twoButtonColor = Color.Grey; 317 }) 318 319 Button('Third Button') 320 .width(260) 321 .height(70) 322 .backgroundColor(this.threeButtonColor) 323 .fontColor(Color.Black) 324 // Listen for the focus obtaining event of the third component and change its color when it obtains focus. 325 .onFocus(() => { 326 this.threeButtonColor = Color.Green; 327 }) 328 // Listen for the focus loss event of the third component and change its color when it loses focus. 329 .onBlur(() => { 330 this.threeButtonColor = Color.Gray ; 331 }) 332 }.width('100%').margin({ top: 20 }) 333 } 334} 335``` 336 337 338 339 340 341The preceding example includes three steps: 342 343- When the application is opened, pressing the **Tab** key activates focus traversal, **First Button** displays a focus state style – a blue bounding box around the component – and its **onFocus** callback is triggered, changing the background color to green. 344- When the **Tab** key is pressed again, **Second Button** gains focus, triggering its **onFocus** callbacktriggered, and its background color turns green, while **First Button** loses focus, triggering its **onBlur** callback, and its background color reverts to gray. 345- A subsequent **Tab** key press causes **Third Button** to gain focus, triggering its **onFocus** callback, and its background color turns green. Concurrently, **Second Button** loses focus, triggering its **onBlur** callback, and its background color reverts to gray. 346 347When both parent and child nodes have focus acquisition and loss events simultaneously, the order of event responses is as follows: 348 349Parent node **Row1** loses focus -> Child node **Button1** loses focus -> Child node **Button2** gains focus -> Parent node **Row2** gains focus 350 351```ts 352@Entry 353@Component 354struct FocusAndBlurExample { 355 build() { 356 Column() { 357 Column({ space: 5 }) { 358 Row() { // Parent node Row1 359 Button('Button1') // Child node Button1 360 .width(140) 361 .height(45) 362 .margin(5) 363 .onFocus(() => { 364 console.log("Button1 onFocus"); 365 }) 366 .onBlur(() => { 367 console.log("Button1 onBlur"); 368 }) 369 } 370 .onFocus(() => { 371 console.log("Row1 onFocus"); 372 }) 373 .onBlur(() => { 374 console.log("Row1 onBlur"); 375 }) 376 377 Row() { // Parent node Row2 378 Button('Button2') // Child node Button2 379 .width(140) 380 .height(45) 381 .margin(5) 382 .onFocus(() => { 383 console.log("Button2 onFocus"); 384 }) 385 .onBlur(() => { 386 console.log("Button2 onBlur"); 387 }) 388 } 389 .onFocus(() => { 390 console.log("Row2 onFocus"); 391 }) 392 .onBlur(() => { 393 console.log("Row2 onBlur"); 394 }) 395 }.width('100%').margin({ top: 5 }) 396 }.width('100%') 397 } 398} 399``` 400 401When focus moves from **Button1** to **Button2**, the log printing order is as follows: 402```ts 403Row1 onBlur 404Button1 onBlur 405Button2 onFocus 406Row2 onFocus 407``` 408 409## Setting Whether a Component Is Focusable 410 411```ts 412focusable(value: boolean) 413``` 414 415Sets whether the component is focusable. 416 417Components can be classified into the following types based on their focus capability: 418 419- Default focusable components: These components are usually interactive components, such as **Button**, **Checkbox**, and **TextInput**. 420 421- Components with focus capability but not focusable by default: Typical examples are **Text** and **Image**. To enable them to be focusable, set **focusable(true)**. When these components do not have the **focusable** attribute set, setting an **onClick** event or a single-tap gesture implicitly makes them focusable. However, when these components have the **focusable** attribute set to **false**, they are still not focusable even if you bind the aforementioned event or gesture to them. 422 423- Non-focusable components: Components that do not allow for interactions, such as **Blank** and **Circle**, cannot be made focusable, even with the **focusable** attribute applied. 424 425 426```ts 427enabled(value: boolean) 428``` 429 430Sets the component's interactivity. If [enabled](../reference/apis-arkui/arkui-ts/ts-universal-attributes-enable.md#enabled) is set to **false**, the component becomes non-interactive and cannot gain focus. 431 432 433```ts 434visibility(value: Visibility) 435``` 436 437Sets the component's visibility. If [visibility](../reference/apis-arkui/arkui-ts/ts-universal-attributes-visibility.md#visibility) set to **Visibility.None** or **Visibility.Hidden**, the component becomes invisible and cannot gain focus. 438 439 440```ts 441focusOnTouch(value: boolean) 442``` 443 444Sets whether the component is focusable on touch. 445 446 447> **NOTE** 448> 449>When a component that is currently focused has its **focusable** or **enabled** attribute set to **false**, it automatically loses focus. The focus then shifts to another component according to the [Focus Traversal Guidelines](#focus-traversal-guidelines). 450 451 452```ts 453// xxx.ets 454@Entry 455@Component 456struct FocusableExample { 457 @State textFocusable: boolean = true; 458 @State textEnabled: boolean = true; 459 @State color1: Color = Color.Yellow; 460 @State color2: Color = Color.Yellow; 461 @State color3: Color = Color.Yellow; 462 463 build() { 464 Column({ space: 5 }) { 465 Text('Default Text') // The first Text component does not have the focusable attribute set, and is not focusable by default. 466 .borderColor(this.color1) 467 .borderWidth(2) 468 .width(300) 469 .height(70) 470 .onFocus(() => { 471 this.color1 = Color.Blue; 472 }) 473 .onBlur(() => { 474 this.color1 = Color.Yellow; 475 }) 476 Divider() 477 478 Text('focusable: ' + this.textFocusable) // The second Text component initially has focusable set to true and focusableOnTouch true. 479 .borderColor(this.color2) 480 .borderWidth(2) 481 .width(300) 482 .height(70) 483 .focusable(this.textFocusable) 484 .focusOnTouch(true) 485 .onFocus(() => { 486 this.color2 = Color.Blue; 487 }) 488 .onBlur(() => { 489 this.color2 = Color.Yellow; 490 }) 491 492 Text('enabled: ' + this.textEnabled) // The third Text component has focusable set to true, enabled initially true. 493 .borderColor(this.color3) 494 .borderWidth(2) 495 .width(300) 496 .height(70) 497 .focusable(true) 498 .enabled(this.textEnabled) 499 .focusOnTouch(true) 500 .onFocus(() => { 501 this.color3 = Color.Blue; 502 }) 503 .onBlur(() => { 504 this.color3 = Color.Yellow; 505 }) 506 507 Divider() 508 509 Row() { 510 Button('Button1') 511 .width(140).height(70) 512 Button('Button2') 513 .width(160).height(70) 514 } 515 516 Divider() 517 Button('Button3') 518 .width(300).height(70) 519 520 Divider() 521 }.width('100%').justifyContent(FlexAlign.Center) 522 .onKeyEvent((e) => { 523 // Bind onKeyEvent. When this Column component has focus, pressing F will toggle the focusable state of the second Text component. 524 if (e.keyCode === 2022 && e.type === KeyType.Down) { 525 this.textFocusable = !this.textFocusable; 526 } 527 // Bind onKeyEvent. When this Column component has focus, pressing G will toggle the enabled state of the third Text component. 528 if (e.keyCode === 2023 && e.type === KeyType.Down) { 529 this.textEnabled = !this.textEnabled; 530 } 531 }) 532 } 533} 534``` 535 536 537Operation result: 538 539 540 541 542The preceding example includes three steps: 543 544 545- As the first **Text** component does not have **focusable(true)** set, it is not focusable. 546- The second **Text** component is set with **focusOnTouch(true)**, allowing it to gain focus on touch. Pressing the **Tab** key triggers focus traversal, but the focus remains on the second component. When the **F** key is pressed, the **onKeyEvent** callback toggles **focusable** to **false**, making the second **Text** component not focusable, and the focus shifts to the next available focusable component, which is the third **Text** component. 547- Pressing the **G** key triggers the **onKeyEvent** callback, which sets **enabled** to **false**, making the third **Text** component not focusable. The focus then automatically moves to the **Row** container, where the default configuration causes the focus to shift to **Button1**. 548 549## Setting the Focus Box for a Container 550 551Although container components can gain focus, they are unable to draw a focus box by themselves. To enable focus box drawing for a container, you can configure an **onClick** event or a single-finger tap gesture on the container. 552 553> **NOTE** 554> 555> Prerequisites for drawing a focus box on a container: 556> - The container has no focusable child nodes. 557> - The container has an **onClick** event or a single-finger tap gesture configured. 558> - The container itself does not have the **focusable** attribute set, or the **focusable** attribute is set after the **onClick** event or single-finger tap gesture is configured. 559 560```ts 561@Entry 562@Component 563struct ScopeFocusExample { 564 @State scopeFocusState: boolean = true; 565 566 build() { 567 Column() { 568 Column({ space: 5 }) { 569 Text("Container focus").textAlign(TextAlign.Center) 570 } 571 .justifyContent(FlexAlign.Center) 572 .width('80%') 573 .height(50) 574 .margin({ top: 5, bottom: 5 }) 575 .onClick(() => { 576 }) 577 .focusable(this.scopeFocusState) 578 579 Button('Button1') 580 .width(140) 581 .height(45) 582 .margin(5) 583 .onClick(() => { 584 this.scopeFocusState = !this.scopeFocusState; 585 console.log("Button1 onFocus"); 586 }) 587 Button('Button2') 588 .width(140) 589 .height(45) 590 .margin(5) 591 }.width('100%') 592 } 593} 594``` 595 596 597 598 599The preceding example includes two steps: 600- After the **onClick** event and **focusable** is set to **true** for the **Column** container, the container can draw a focus box when the **Tab** key is used for focus traversal. 601- When **Button1** is clicked, the **focusable** attribute of the **Column** container is set to **false**, preventing the container from gaining focus and drawing a focus box. 602 603## Setting Focus to Stop on a Container 604 605```ts 606tabStop(isTabStop: boolean) 607``` 608Use the [tabStop](../reference/apis-arkui/arkui-ts/ts-universal-attributes-focus.md#tabstop14) API to control whether the focus will stop on the container during focus traversal. 609 610```ts 611@Entry 612@Component 613struct TabStopExample { 614 build() { 615 Column({ space: 20 }) { 616 Button('Button1') 617 .width(140) 618 .height(45) 619 .margin(5) 620 Column() { 621 Button('Button2') 622 .width(140) 623 .height(45) 624 .margin(5) 625 Button('Button3') 626 .width(140) 627 .height(45) 628 .margin(5) 629 }.tabStop(true) 630 }.width('100%') 631 } 632} 633``` 634 635 636 637The preceding example includes two steps: 638- When **tabStop** is set to **true** on the **Column** component, pressing the **Tab** key will cycle focus between **Button1** and the **Column** container. The **Column** container shows a focus box when it gains focus. 639- Once the **Column** container gains focus, pressing **Enter** moves the focus to the first focusable element inside the container. Further **Tab** key presses will move focus through other focusable elements within the container. 640 641## Default Focus 642 643### Default Focus on a Page 644 645```ts 646defaultFocus(value: boolean) 647``` 648 649Specifies whether to set the component as the default focus of the page. 650 651 652```ts 653// xxx.ets 654@Entry 655@Component 656struct morenjiaodian { 657 @State oneButtonColor: Color = Color.Gray; 658 @State twoButtonColor: Color = Color.Gray; 659 @State threeButtonColor: Color = Color.Gray; 660 661 build() { 662 Column({ space: 20 }) { 663 // 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. 664 Button('First Button') 665 .width(260) 666 .height(70) 667 .backgroundColor(this.oneButtonColor) 668 .fontColor(Color.Black) 669 // Listen for the focus obtaining event of the first component and change its color when it obtains focus. 670 .onFocus(() => { 671 this.oneButtonColor = Color.Green; 672 }) 673 // Listen for the focus loss event of the first component and change its color when it loses focus. 674 .onBlur(() => { 675 this.oneButtonColor = Color.Gray; 676 }) 677 678 Button('Second Button') 679 .width(260) 680 .height(70) 681 .backgroundColor(this.twoButtonColor) 682 .fontColor(Color.Black) 683 // Listen for the focus obtaining event of the second component and change its color when it obtains focus. 684 .onFocus(() => { 685 this.twoButtonColor = Color.Green; 686 }) 687 // Listen for the focus loss event of the second component and change its color when it loses focus. 688 .onBlur(() => { 689 this.twoButtonColor = Color.Grey; 690 }) 691 692 Button('Third Button') 693 .width(260) 694 .height(70) 695 .backgroundColor(this.threeButtonColor) 696 .fontColor(Color.Black) 697 // Set the default focus. 698 .defaultFocus(true) 699 // Listen for the focus obtaining event of the third component and change its color when it obtains focus. 700 .onFocus(() => { 701 this.threeButtonColor = Color.Green; 702 }) 703 // Listen for the focus loss event of the third component and change its color when it loses focus. 704 .onBlur(() => { 705 this.threeButtonColor = Color.Gray ; 706 }) 707 }.width('100%').margin({ top: 20 }) 708 } 709} 710``` 711 712 713 714The preceding example includes two steps: 715 716- The **defaultFocus(true)** is set on the third **Button** component, which means it gains focus by default when the page is loaded, displaying in green. 717- Pressing the **Tab** key triggers focus traversal, and since the third **Button** component is in focus, a focus frame appears around it. 718 719### Default Focus for Containers 720 721The default focus within a container is affected by [focus priority](#focus-group-and-focus-priority). 722 723**Differences Between defaultFocus and FocusPriority** 724 725[defaultFocus](../reference/apis-arkui/arkui-ts/ts-universal-attributes-focus.md#defaultfocus9) specifies the initial focus when the page loads. [FocusPriority](../reference/apis-arkui/arkui-ts/ts-universal-attributes-focus.md#focuspriority12) defines the order in which child components gain focus within a container. Behavior is undefined when both attributes are set in some scenarios. For example, a page's initial display cannot simultaneously meet the focus requirements of a component with **defaultFocus **and a high-priority component. 726 727Example 728 729```ts 730@Entry 731@Component 732struct Index { 733 build() { 734 Row() { 735 Button('Button1') 736 .defaultFocus(true) 737 Button('Button2') 738 .focusScopePriority('RowScope', FocusPriority.PREVIOUS) 739 }.focusScopeId('RowScope') 740 } 741} 742``` 743 744### Focus Chain for Pages/Containers 745 746**Overall Focus and Non-Overall Focus** 747 748- Overall focus: The entire page or container gains focus first, then the focus shifts to its child components. Examples include page transitions, route switches within **Navigation** components, focus group traversal, and when a container component proactively calls **requestFocusById**. 749 750- Non-overall focus: A specific component gains focus, pulling its parent components into focus. Examples include a **TextInput** component proactively obtaining focus or using the **Tab** key for traversal in non-focus group. 751 752**Formation of the Focus Chain in Overall Focus** 753 7541. Initial page focus: 755 756- The leaf node of the focus chain is the node with **defaultFocus** set. 757 758- If no **defaultFocus** is configured, the focus remains on the page's root container. 759 7602. Subsequent page focus: Focus is gained by the node that last held focus. 761 7623. Focus chain with priority configuration: 763 764- If a container has a component with a focus priority higher than **PREVIOUS**, the component with the highest priority gains focus. 765 766- If no component with a priority higher than **PREVIOUS** exists, the last focused node regains focus, such as when a window refocuses after being out of focus. 767 768 769## Focus Style 770 771> **NOTE** 772> 773> When a component is in the focused state, its [zIndex](../reference/apis-arkui/arkui-ts/ts-universal-attributes-z-order.md#zindex) value is automatically elevated to **INT_MAX** to ensure that it is rendered above other components. If the component already has a specified **zIndex** value, this value will not be adjusted. When the component exits the focused state (for example, loses focus or leaves the focus chain), its **zIndex** value will revert to its original settings. 774> 775 776```ts 777focusBox(style: FocusBoxStyle) 778``` 779 780Sets the system focus box style for the component. 781 782```ts 783import { ColorMetrics, LengthMetrics } from '@kit.ArkUI' 784 785@Entry 786@Component 787struct RequestFocusExample { 788 build() { 789 Column({ space: 30 }) { 790 Button("small black focus box") 791 .focusBox({ 792 margin: new LengthMetrics(0), 793 strokeColor: ColorMetrics.rgba(0, 0, 0), 794 }) 795 Button("large red focus box") 796 .focusBox({ 797 margin: LengthMetrics.px(20), 798 strokeColor: ColorMetrics.rgba(255, 0, 0), 799 strokeWidth: LengthMetrics.px(10) 800 }) 801 } 802 .alignItems(HorizontalAlign.Center) 803 .width('100%') 804 } 805} 806``` 807 808 809 810 811The preceding example includes two steps: 812 813- After the page opens, pressing the Tab key initiates focus traversal. The first **Button** gains focus, displaying a small, black focus box that is closely fitted to the edge. 814- Pressing the Tab key again shifts focus to the second **Button**, which features a large, red focus box with a thicker stroke and a more significant margin from the edge. 815 816## Active Focus Acquisition/Loss 817 818- Using **FocusController** APIs 819 820 You are advised to use **requestFocus** from **FocusController** for actively acquiring focus. It provides the following benefits: 821 - Takes effect in the current frame, preventing interference from subsequent component tree changes. 822 - Provides exception handling, aiding in troubleshooting focus acquisition issues. 823 - Prevents errors in multi-instance scenarios by avoiding incorrect instance retrieval. 824 825 You must first obtain an instance using the [getFocusController()](../reference/apis-arkui/js-apis-arkui-UIContext.md#getfocuscontroller12) API in **UIContext** and then use this instance to call the corresponding methods. 826 827 ```ts 828 requestFocus(key: string): void 829 ``` 830 Transfers focus to a component node by the component ID, which is effective immediately. 831 832 ```ts 833 clearFocus(): void 834 ``` 835 Clears the focus and forcibly moves the focus to the root container node of the page, causing other nodes in the focus chain to lose focus. 836 837- Using **focusControl** APIs 838 ```ts 839 requestFocus(value: string): boolean 840 ``` 841 842 Moves focus to a specified component, with the change taking effect in the next frame. 843 844 845```ts 846// focusTest.ets 847@Entry 848@Component 849struct RequestExample { 850 @State btColor: string = '#ff2787d9' 851 @State btColor2: string = '#ff2787d9' 852 853 build() { 854 Column({ space: 20 }) { 855 Column({ space: 5 }) { 856 Button('Button') 857 .width(200) 858 .height(70) 859 .fontColor(Color.White) 860 .focusOnTouch(true) 861 .backgroundColor(this.btColor) 862 .onFocus(() => { 863 this.btColor = '#ffd5d5d5' 864 }) 865 .onBlur(() => { 866 this.btColor = '#ff2787d9' 867 }) 868 .id("testButton") 869 870 Button('Button') 871 .width(200) 872 .height(70) 873 .fontColor(Color.White) 874 .focusOnTouch(true) 875 .backgroundColor(this.btColor2) 876 .onFocus(() => { 877 this.btColor2 = '#ffd5d5d5' 878 }) 879 .onBlur(() => { 880 this.btColor2 = '#ff2787d9' 881 }) 882 .id("testButton2") 883 884 Divider() 885 .vertical(false) 886 .width("80%") 887 .backgroundColor('#ff707070') 888 .height(10) 889 890 Button('FocusController.requestFocus') 891 .width(200).height(70).fontColor(Color.White) 892 .onClick(() => { 893 this.getUIContext().getFocusController().requestFocus("testButton") 894 }) 895 .backgroundColor('#ff2787d9') 896 897 Button("focusControl.requestFocus") 898 .width(200).height(70).fontColor(Color.White) 899 .onClick(() => { 900 focusControl.requestFocus("testButton2") 901 }) 902 .backgroundColor('#ff2787d9') 903 904 Button("clearFocus") 905 .width(200).height(70).fontColor(Color.White) 906 .onClick(() => { 907 this.getUIContext().getFocusController().clearFocus() 908 }) 909 .backgroundColor('#ff2787d9') 910 } 911 } 912 .width('100%') 913 .height('100%') 914 } 915} 916``` 917 918 919 920The preceding example includes three steps: 921 922- When the **FocusController.requestFocus** button is clicked, the first button gains focus. 923- When the **focusControl.requestFocus** button is clicked, the second button gains focus. 924- When the **clearFocus** button is clicked, the second button loses focus. 925 926## Customizing the Tab Focus Order 927```ts 928tabIndex(index: number) 929``` 930 931Use **tabIndex** to control the order in which components receive focus when the **Tab** key is used for focus traversal. 932 933When 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. 934 935> **NOTE** 936> 937> **tabIndex** and **focusScopeId** cannot be both set on the same component. 938 939```ts 940@Entry 941@Component 942struct TabIndexExample { 943 build() { 944 Column() { 945 Button('Button1') 946 .width(140) 947 .height(45) 948 .margin(5) 949 Button('Focus Button1') 950 .width(140) 951 .height(45) 952 .margin(5).tabIndex(1) 953 Button('Button2') 954 .width(140) 955 .height(45) 956 .margin(5) 957 Button('Focus Button2') 958 .width(140) 959 .height(45) 960 .margin(5).tabIndex(2) 961 }.width('100%') 962 } 963} 964``` 965 966Pressing the **Tab** key moves focus only between components with **tabIndex** values. 967 968 969 970When **tabIndex** is set on a container: If no child component has ever gained focus, focus goes to the first focusable child component; otherwise, focus goes to the last child that previously had focus. 971 972```ts 973@Entry 974@Component 975struct TabIndexExample2 { 976 build() { 977 Column() { 978 Button('Focus Button1') 979 .width(140) 980 .height(45) 981 .margin(5).tabIndex(1) 982 Column() { 983 Button('Button1') 984 .width(140) 985 .height(45) 986 .margin(5) 987 Button('Button2') 988 .width(140) 989 .height(45) 990 .margin(5) 991 }.tabIndex(2) 992 }.width('100%') 993 } 994} 995``` 996 997Tab focus traversal with **tabIndex** on a container 998 999 1000 1001The preceding example includes three steps: 1002 1003- When the **Tab** key is pressed, focus moves between **Button1** and **Button2** (as their parent container has **tabIndex** set). 1004- When focus is on **Button2**, using the down arrow key moves focus to **Button3**. 1005- When the **Tab** key is used for focus traversal, focus moves between **Button1** and **Button3**. 1006 1007## Focus Group and Focus Priority 1008 1009```ts 1010focusScopePriority(scopeId: string, priority?: FocusPriority) 1011``` 1012 1013Sets the focus priority of this component in a specified container. It must be used together with **focusScopeId**. 1014 1015 1016```ts 1017focusScopeId(id: string, isGroup?: boolean) 1018``` 1019 1020Assigns an ID to this container component and specifies whether the container is a focus group. Focus groups should not be mixed with **tabIndex** usage. 1021 1022```ts 1023// focusTest.ets 1024@Entry 1025@Component 1026struct FocusableExample { 1027 @State inputValue: string = '' 1028 1029 build() { 1030 Scroll() { 1031 Row({ space: 20 }) { 1032 Column({ space: 20 }) { // Labeled as Column1. 1033 Column({ space: 5 }) { 1034 Button('Group1') 1035 .width(165) 1036 .height(40) 1037 .fontColor(Color.White) 1038 Row({ space: 5 }) { 1039 Button() 1040 .width(80) 1041 .height(40) 1042 .fontColor(Color.White) 1043 Button() 1044 .width(80) 1045 .height(40) 1046 .fontColor(Color.White) 1047 } 1048 Row({ space: 5 }) { 1049 Button() 1050 .width(80) 1051 .height(40) 1052 .fontColor(Color.White) 1053 Button() 1054 .width(80) 1055 .height(40) 1056 .fontColor(Color.White) 1057 } 1058 }.borderWidth(2).borderColor(Color.Red).borderStyle(BorderStyle.Dashed) 1059 Column({ space: 5 }) { 1060 Button('Group2') 1061 .width(165) 1062 .height(40) 1063 .fontColor(Color.White) 1064 Row({ space: 5 }) { 1065 Button() 1066 .width(80) 1067 .height(40) 1068 .fontColor(Color.White) 1069 Button() 1070 .width(80) 1071 .height(40) 1072 .fontColor(Color.White) 1073 .focusScopePriority('ColumnScope1', FocusPriority.PRIOR) // Focuses when Column1 first gains focus. 1074 } 1075 Row({ space: 5 }) { 1076 Button() 1077 .width(80) 1078 .height(40) 1079 .fontColor(Color.White) 1080 Button() 1081 .width(80) 1082 .height(40) 1083 .fontColor(Color.White) 1084 } 1085 }.borderWidth(2).borderColor(Color.Green).borderStyle(BorderStyle.Dashed) 1086 } 1087 .focusScopeId('ColumnScope1') 1088 Column({ space: 5 }) { // Labeled as Column2. 1089 TextInput({placeholder: 'input', text: this.inputValue}) 1090 .onChange((value: string) => { 1091 this.inputValue = value 1092 }) 1093 .width(156) 1094 Button('Group3') 1095 .width(165) 1096 .height(40) 1097 .fontColor(Color.White) 1098 Row({ space: 5 }) { 1099 Button() 1100 .width(80) 1101 .height(40) 1102 .fontColor(Color.White) 1103 Button() 1104 .width(80) 1105 .height(40) 1106 .fontColor(Color.White) 1107 } 1108 Button() 1109 .width(165) 1110 .height(40) 1111 .fontColor(Color.White) 1112 .focusScopePriority('ColumnScope2', FocusPriority.PREVIOUS) // Focuses when Column2 first gains focus. 1113 Row({ space: 5 }) { 1114 Button() 1115 .width(80) 1116 .height(40) 1117 .fontColor(Color.White) 1118 Button() 1119 .width(80) 1120 .height(40) 1121 .fontColor(Color.White) 1122 } 1123 Button() 1124 .width(165) 1125 .height(40) 1126 .fontColor(Color.White) 1127 Row({ space: 5 }) { 1128 Button() 1129 .width(80) 1130 .height(40) 1131 .fontColor(Color.White) 1132 Button() 1133 .width(80) 1134 .height(40) 1135 .fontColor(Color.White) 1136 } 1137 }.borderWidth(2).borderColor(Color.Orange).borderStyle(BorderStyle.Dashed) 1138 .focusScopeId('ColumnScope2', true) // Column2 is a focus group. 1139 }.alignItems(VerticalAlign.Top) 1140 } 1141 } 1142} 1143``` 1144 1145 1146 1147 1148 1149 1150The preceding example includes two steps: 1151 1152- The **TextInput** component is part of a focus group. When the **Tab** key is pressed, the focus quickly moves out of the **TextInput** component to the next focusable element outside the group. Arrow keys can be used to move focus within the **TextInput** component. 1153- The **Column** component in the upper left corner does not have a focus group set. Therefore, focus can only be traversed one by one with the **Tab** key. 1154 1155 1156In API version 14, you can use the **arrowStepOut** parameter on a focus group to specify whether focus can move out of the group using arrow keys. 1157```ts 1158focusScopeId(id: string, isGroup?: boolean, arrowStepOut?: boolean) 1159``` 1160 1161```ts 1162@Entry 1163@Component 1164struct FocusScopeIdExample { 1165 build() { 1166 Column({ space: 20 }) { 1167 Column() { 1168 Button('Group1') 1169 .width(165) 1170 .height(40) 1171 .margin(5) 1172 .fontColor(Color.White) 1173 Row({ space: 5 }) { 1174 Button("Button1") 1175 .width(80) 1176 .height(40) 1177 .margin(5) 1178 .fontColor(Color.White) 1179 Button("Button2") 1180 .width(80) 1181 .height(40) 1182 .margin(5) 1183 .fontColor(Color.White) 1184 } 1185 }.focusScopeId("1", true, true) 1186 .borderWidth(2).borderColor(Color.Red).borderStyle(BorderStyle.Dashed) 1187 1188 TextInput() 1189 Column() { 1190 Button('Group2') 1191 .width(165) 1192 .height(40) 1193 .margin(5) 1194 .fontColor(Color.White) 1195 Row({ space: 5 }) { 1196 Button("Button3") 1197 .width(80) 1198 .height(40) 1199 .margin(5) 1200 .fontColor(Color.White) 1201 Button("Button4") 1202 .width(80) 1203 .height(40) 1204 .margin(5) 1205 .fontColor(Color.White) 1206 } 1207 }.focusScopeId("2", true, false) 1208 .borderWidth(2).borderColor(Color.Green).borderStyle(BorderStyle.Dashed) 1209 1210 TextInput() 1211 }.width('100%') 1212 } 1213} 1214``` 1215 1216 1217 1218 1219The preceding example includes three steps: 1220- **Group1** and **Group2** are defined as focus groups using **focusScopeId**. When the **Tab** key is pressed, focus quickly moves between these groups, skipping over individual buttons within the groups. 1221- **Group1** is configured with **arrowStepOut** set to **true**, allowing focus to move out of the group using arrow keys. When focus is within **Group1**, arrow keys can be used to move focus to the **TextInput** component outside the group. 1222- **Group2** is configured with **arrowStepOut** set to **false**, preventing focus from moving out of the group using arrow keys. When focus is within **Group2**, arrow keys cannot be used to move focus to the **TextInput** component outside the group. 1223 1224> **NOTE** 1225> 1226> The **TextInput** component has its own handling for arrow keys, so you cannot directly move focus out of it using arrow keys. 1227 1228## Focus and Key Events 1229 1230When a component is in focus and has either an **onClick** or **TapGesture** event defined, pressing the **Enter** key or spacebar triggers the associated event callback. 1231 1232> **NOTE** 1233> 1234> 1. If the **onClick** or **TapGesture** event is triggered by pressing the **Enter** key or spacebar, the event does not bubble up by default. This means that the parent component's corresponding [key event](../reference/apis-arkui/arkui-ts/ts-universal-events-key.md) is not triggered synchronously. 1235> 2. The key event (**onKeyEvent**) bubbles up by default, which means that it will also trigger the parent component's key event callback. 1236> 3. If the component has both an **onClick** event and an **onKeyEvent**, pressing the **Enter** key or spacebar trigger both events. 1237> 4. The component's response to the **onClick** event is independent of whether the focus is activated or not. 1238 1239```ts 1240@Entry 1241@Component 1242struct FocusOnclickExample { 1243 @State count: number = 0 1244 @State name: string = 'Button' 1245 1246 build() { 1247 Column() { 1248 Button(this.name) 1249 .fontSize(30) 1250 .onClick(() => { 1251 this.count++ 1252 if (this.count <= 0) { 1253 this.name = "count is negative number" 1254 } else if (this.count % 2 === 0) { 1255 this.name = "count is even number" 1256 } else { 1257 this.name = "count is odd number" 1258 } 1259 }).height(60) 1260 }.height('100%').width('100%').justifyContent(FlexAlign.Center) 1261 } 1262} 1263``` 1264 1265 1266## Component Focusability 1267 1268 1269 **Table 1** Focusability of basic components 1270 1271| Basic Component | Focusable| Default Value of focusable| 1272| ---------------------------------------- | ------- | ------------ | 1273| [AlphabetIndexer](../reference/apis-arkui/arkui-ts/ts-container-alphabet-indexer.md) | Yes | true | 1274| [Blank](../reference/apis-arkui/arkui-ts/ts-basic-components-blank.md) | No | false | 1275| [Button](../reference/apis-arkui/arkui-ts/ts-basic-components-button.md) | Yes | true | 1276| [CalendarPicker](../reference/apis-arkui/arkui-ts/ts-basic-components-calendarpicker.md) | Yes | true | 1277| [Checkbox](../reference/apis-arkui/arkui-ts/ts-basic-components-checkbox.md) | Yes | true | 1278| [CheckboxGroup](../reference/apis-arkui/arkui-ts/ts-basic-components-checkboxgroup.md) | Yes | true | 1279| [ContainerSpan](../reference/apis-arkui/arkui-ts/ts-basic-components-containerspan.md) | No | false | 1280| [DataPanel](../reference/apis-arkui/arkui-ts/ts-basic-components-datapanel.md) | Yes | false | 1281| [DatePicker](../reference/apis-arkui/arkui-ts/ts-basic-components-datepicker.md) | Yes | true | 1282| [Divider](../reference/apis-arkui/arkui-ts/ts-basic-components-divider.md) | Yes | false | 1283| [Gauge](../reference/apis-arkui/arkui-ts/ts-basic-components-gauge.md) | Yes | false | 1284| [Image](../reference/apis-arkui/arkui-ts/ts-basic-components-image.md) | Yes | false | 1285| [ImageAnimator](../reference/apis-arkui/arkui-ts/ts-basic-components-imageanimator.md) | No | false | 1286| [ImageSpan](../reference/apis-arkui/arkui-ts/ts-basic-components-imagespan.md) | No | false | 1287| [LoadingProgress](../reference/apis-arkui/arkui-ts/ts-basic-components-loadingprogress.md) | Yes | true | 1288| [Marquee](../reference/apis-arkui/arkui-ts/ts-basic-components-marquee.md) | No | false | 1289| [Menu](../reference/apis-arkui/arkui-ts/ts-basic-components-menu.md) | Yes | true | 1290| [MenuItem](../reference/apis-arkui/arkui-ts/ts-basic-components-menuitem.md) | Yes | true | 1291| [MenuItemGroup](../reference/apis-arkui/arkui-ts/ts-basic-components-menuitemgroup.md) | No | false | 1292| [Navigation](../reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md) | Yes | true | 1293| [NavRouter](../reference/apis-arkui/arkui-ts/ts-basic-components-navrouter.md) | No | false | 1294| [NavDestination](../reference/apis-arkui/arkui-ts/ts-basic-components-navdestination.md) | Yes | true | 1295| [PatternLock](../reference/apis-arkui/arkui-ts/ts-basic-components-patternlock.md) | Yes | true | 1296| [Progress](../reference/apis-arkui/arkui-ts/ts-basic-components-progress.md) | Yes | true | 1297| [QRCode](../reference/apis-arkui/arkui-ts/ts-basic-components-qrcode.md) | Yes | true | 1298| [Radio](../reference/apis-arkui/arkui-ts/ts-basic-components-radio.md) | Yes | true | 1299| [Rating](../reference/apis-arkui/arkui-ts/ts-basic-components-rating.md) | Yes | true | 1300| [RichEditor](../reference/apis-arkui/arkui-ts/ts-basic-components-richeditor.md) | Yes | true | 1301| [RichText](../reference/apis-arkui/arkui-ts/ts-basic-components-richtext.md) | No | false | 1302| [ScrollBar](../reference/apis-arkui/arkui-ts/ts-basic-components-scrollbar.md) | No | false | 1303| [Search](../reference/apis-arkui/arkui-ts/ts-basic-components-search.md) | Yes | true | 1304| [Select](../reference/apis-arkui/arkui-ts/ts-basic-components-select.md) | Yes | true | 1305| [Slider](../reference/apis-arkui/arkui-ts/ts-basic-components-slider.md) | Yes | true | 1306| [Span](../reference/apis-arkui/arkui-ts/ts-basic-components-span.md) | No | false | 1307| [Stepper](../reference/apis-arkui/arkui-ts/ts-basic-components-stepper.md) | Yes | true | 1308| [StepperItem](../reference/apis-arkui/arkui-ts/ts-basic-components-stepperitem.md) | Yes | true | 1309| [SymbolSpan](../reference/apis-arkui/arkui-ts/ts-basic-components-symbolSpan.md) | No | false | 1310| [SymbolGlyph](../reference/apis-arkui/arkui-ts/ts-basic-components-symbolGlyph.md) | No | false | 1311| [Text](../reference/apis-arkui/arkui-ts/ts-basic-components-text.md) | Yes | false | 1312| [TextArea](../reference/apis-arkui/arkui-ts/ts-basic-components-textarea.md) | No | false | 1313| [TextClock](../reference/apis-arkui/arkui-ts/ts-basic-components-textclock.md) | No | false | 1314| [TextInput](../reference/apis-arkui/arkui-ts/ts-basic-components-textinput.md) | Yes | true | 1315| [TextPicker](../reference/apis-arkui/arkui-ts/ts-basic-components-textpicker.md) | Yes | true | 1316| [TextTimer](../reference/apis-arkui/arkui-ts/ts-basic-components-texttimer.md) | No | false | 1317| [TimePicker](../reference/apis-arkui/arkui-ts/ts-basic-components-timepicker.md) | No | false | 1318| [Toggle](../reference/apis-arkui/arkui-ts/ts-basic-components-toggle.md) | Yes | true | 1319| [XComponent](../reference/apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) | Yes | false | 1320 1321 **Table 2** Focusability of container components 1322 1323| Container Component | Focusable| Default Value of focusable| 1324| ---------------------------------------- | ----- | ------------ | 1325| [Badge](../reference/apis-arkui/arkui-ts/ts-container-badge.md) | No | false | 1326| [Column](../reference/apis-arkui/arkui-ts/ts-container-column.md) | Yes | true | 1327| [ColumnSplit](../reference/apis-arkui/arkui-ts/ts-container-columnsplit.md) | Yes | true | 1328| [Counter](../reference/apis-arkui/arkui-ts/ts-container-counter.md) | Yes | false | 1329| [EmbeddedComponent](../reference/apis-arkui/arkui-ts/ts-container-embedded-component.md) | No | false | 1330| [Flex](../reference/apis-arkui/arkui-ts/ts-container-flex.md) | Yes | true | 1331| [FlowItem](../reference/apis-arkui/arkui-ts/ts-container-flowitem.md) | Yes | true | 1332| [FolderStack](../reference/apis-arkui/arkui-ts/ts-container-folderstack.md) | Yes | true | 1333| [FormLink](../reference/apis-arkui/arkui-ts/ts-container-formlink.md) | No | false | 1334| [GridCol](../reference/apis-arkui/arkui-ts/ts-container-gridcol.md) | Yes | true | 1335| [GridRow](../reference/apis-arkui/arkui-ts/ts-container-gridrow.md) | Yes | true | 1336| [Grid](../reference/apis-arkui/arkui-ts/ts-container-grid.md) | Yes | true | 1337| [GridItem](../reference/apis-arkui/arkui-ts/ts-container-griditem.md) | Yes | true | 1338| [Hyperlink](../reference/apis-arkui/arkui-ts/ts-container-hyperlink.md) | Yes | true | 1339| [List](../reference/apis-arkui/arkui-ts/ts-container-list.md) | Yes | true | 1340| [ListItem](../reference/apis-arkui/arkui-ts/ts-container-listitem.md) | Yes | true | 1341| [ListItemGroup](../reference/apis-arkui/arkui-ts/ts-container-listitemgroup.md) | Yes | true | 1342| [Navigator](../reference/apis-arkui/arkui-ts/ts-container-navigator.md) | Yes | true | 1343| [Refresh](../reference/apis-arkui/arkui-ts/ts-container-refresh.md) | Yes | true | 1344| [RelativeContainer](../reference/apis-arkui/arkui-ts/ts-container-relativecontainer.md) | No | false | 1345| [Row](../reference/apis-arkui/arkui-ts/ts-container-row.md) | Yes | true | 1346| [RowSplit](../reference/apis-arkui/arkui-ts/ts-container-rowsplit.md) | Yes | true | 1347| [Scroll](../reference/apis-arkui/arkui-ts/ts-container-scroll.md) | Yes | true | 1348| [SideBarContainer](../reference/apis-arkui/arkui-ts/ts-container-sidebarcontainer.md) | Yes | true | 1349| [Stack](../reference/apis-arkui/arkui-ts/ts-container-stack.md) | Yes | true | 1350| [Swiper](../reference/apis-arkui/arkui-ts/ts-container-swiper.md) | Yes | true | 1351| [Tabs](../reference/apis-arkui/arkui-ts/ts-container-tabs.md) | Yes | true | 1352| [TabContent](../reference/apis-arkui/arkui-ts/ts-container-tabcontent.md) | Yes | true | 1353| [WaterFlow](../reference/apis-arkui/arkui-ts/ts-container-waterflow.md) | No | false | 1354| [WithTheme](../reference/apis-arkui/arkui-ts/ts-container-with-theme.md) | Yes | true | 1355 1356 **Table 3** Focusability of media components 1357 1358| Media Component | Focusable| Default Value of focusable| 1359| ---------------------------------------- | ----- | ------------ | 1360| [Video](../reference/apis-arkui/arkui-ts/ts-media-components-video.md) | Yes | true | 1361