• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TextPicker
2
3The **\<TextPicker>** component allows users to scroll to select text.
4
5>  **NOTE**
6>
7>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## Child Components
11
12Not supported
13
14
15## APIs
16
17TextPicker(options?: {range: string[]|Resource, selected?: number, value?: string})
18
19Creates a text picker based on the selection range specified by **range**.
20
21**Parameters**
22
23| Name| Type| Mandatory| Description|
24| -------- | -------- | -------- | -------- |
25| range | string[] \| [Resource](ts-types.md#resource)| Yes| Data selection range of the picker.|
26| selected | number | No| Index of the default item in the range.<br>Default value: **0**|
27| value | string | No| Value of the default item in the range. The priority of this parameter is lower than that of **selected**.<br>Default value: value of the first item|
28
29## Attributes
30
31| Name| Type| Description|
32| -------- | -------- | -------- |
33| defaultPickerItemHeight | number \| string | Height of each item in the picker.|
34
35## Events
36
37In addition to the [universal events](ts-universal-events-click.md), the following events are supported.
38
39| Name| Description|
40| -------- | -------- |
41| onChange(callback: (value: string, index: number) =&gt; void) | Triggered when an item in the picker is selected.<br>- **value**: value of the selected item.<br>- **index**: index of the selected item.|
42
43
44## Example
45
46```ts
47// xxx.ets
48@Entry
49@Component
50struct TextPickerExample {
51  private select: number = 1
52  private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4']
53
54  build() {
55    Column() {
56      TextPicker({ range: this.fruits, selected: this.select })
57        .onChange((value: string, index: number) => {
58          console.info('Picker item changed, value: ' + value + ', index: ' + index)
59        })
60    }
61  }
62}
63```
64
65![en-us_image_0000001257058417](figures/en-us_image_0000001257058417.png)
66