提交 6b51b6de 编写于 作者: E ester.zhou

update ts-universal-attributes-focus.md

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 a7bc82f3
# Focus Control # Focus Control
> **NOTE**<br>
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> This attribute is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions ## Required Permissions
...@@ -12,66 +11,57 @@ None ...@@ -12,66 +11,57 @@ None
## Attributes ## Attributes
| **Name** | **Type** | **Default Value** | **Description** | | Name| Type| Default Value| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| focusable | boolean | false | Whether the current component is focusable. | | focusable | boolean | false | Whether the current component is focusable.|
| tabIndex<sup>9+<sup> | number | 0 | How the current component participates in sequential keyboard navigation.<br>- **tabIndex** >= 0: The component is focusable in sequential keyboard navigation, with its order defined by the value. A component with a larger value is focused after one with a smaller value. If multiple components share the same **tabIndex** value, their focus order follows their position in the component tree.<br>- **tabIndex** < 0 (usually **tabIndex** = -1): The component is focusable, but cannot be reached through sequential keyboard navigation. |
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**<br>
> The following components support focus control: **&lt;Button&gt;**, **&lt;Text&gt;**, **&lt;Image&gt;**, **&lt;List&gt;**, and **&lt;Grid&gt;**. > The following components support focus control: **\<Button>**, **\<Text>**, **\<Image>**, **\<List>**, and **\<Grid>**.
## Example ## Example
```ts
``` // xxx.ets
@Entry @Entry
@Component @Component
struct FocusableExample { struct FocusableExample {
@State textOne: string = '' @State text1: string = 'TabIndex=3'
@State textTwo: string = '' @State text2: string = 'TabIndex=2'
@State textThree: string = 'The third button cannot be focused' @State text3: string = 'focusable=false'
@State oneButtonColor: string = '#FF0000' @State text4: string = 'TabIndex=-1'
@State twoButtonColor: string = '#FFC0CB' @State text5: string = 'TabIndex=1'
@State threeButtonColor: string = '#87CEFA' @State text6: string = 'TabIndex=1'
@State text7: string = 'focusable=true'
@State text8: string = 'focusable=true'
build() { build() {
Column({ space:20 }){ Column({ space:20 }){
Button(this.textOne) Button(this.text1) // This component is the fourth component that is focused when the Tab key is pressed.
.backgroundColor(this.oneButtonColor)
.width(300).height(70).fontColor(Color.Black) .width(300).height(70).fontColor(Color.Black)
.focusable(true) .tabIndex(3)
.onFocus(() => { Button(this.text2) // This component is the third component that is focused when the Tab key is pressed.
this.textOne = 'First Button onFocus'
this.oneButtonColor = '#AFEEEE'
})
.onBlur(() => {
this.textOne = 'First Button onBlur'
this.oneButtonColor = '#FFC0CB'
})
Button(this.textTwo)
.backgroundColor(this.twoButtonColor)
.width(300).height(70).fontColor(Color.Black) .width(300).height(70).fontColor(Color.Black)
.focusable(true) .tabIndex(2)
.onFocus(() => { Button(this.text3) // This component is not focusable.
this.textTwo = 'Second Button onFocus'
this.twoButtonColor = '#AFEEEE'
})
.onBlur(() => {
this.textTwo = 'Second Button onBlur'
this.twoButtonColor = '#FFC0CB'
})
Button(this.textThree)
.backgroundColor(this.threeButtonColor)
.width(300).height(70).fontColor(Color.Black) .width(300).height(70).fontColor(Color.Black)
.focusable(false) .focusable(false)
.onFocus(() => { Button(this.text4) // This component is focusable, but cannot be reached through sequential keyboard navigation.
this.textThree = 'Third Button onFocus' .width(300).height(70).fontColor(Color.Black)
this.threeButtonColor = '#AFEEEE' .tabIndex(-1)
}) Button(this.text5) // This component is the first component that is focused when the Tab key is pressed.
.onBlur(() => { .width(300).height(70).fontColor(Color.Black)
this.textThree = 'Third Button onBlur' .tabIndex(1)
this.threeButtonColor = '#FFC0CB' Button(this.text6) // This component is the second component that is focused when the Tab key is pressed.
}) .width(300).height(70).fontColor(Color.Black)
.tabIndex(1)
Button(this.text7) // This component is the fifth component that is focused when the Tab key is pressed.
.width(300).height(70).fontColor(Color.Black)
.focusable(true)
Button(this.text8) // This component is the sixth component that is focused when the Tab key is pressed.
.width(300).height(70).fontColor(Color.Black)
.focusable(true)
}.width('100%').margin({ top:20 }) }.width('100%').margin({ top:20 })
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册