1# Text Picker Dialog Box (TextPickerDialog) 2 3A text picker dialog box is a dialog box that allows users to select text from the given range. 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> The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see [UIContext](../apis/js-apis-arkui-UIContext.md#uicontext). 10> 11> Since API version 10, you can use the [showTextPickerDialog](../apis/js-apis-arkui-UIContext.md#showtextpickerdialog) API in [UIContext](../apis/js-apis-arkui-UIContext.md#uicontext) to obtain the UI context. 12 13## TextPickerDialog.show 14 15show(options?: TextPickerDialogOptions) 16 17Shows a text picker in the given settings. 18 19**System capability**: SystemCapability.ArkUI.ArkUI.Full 20 21**Parameters** 22 23| Name | Type | Mandatory| Description | 24| ------- | ----------------------------------------------------------- | ---- | -------------------------- | 25| options | [TextPickerDialogOptions](#textpickerdialogoptions) | No | Parameters of the text picker dialog box.| 26 27## TextPickerDialogOptions 28 29This API is extended from [TextPickerOptions](ts-basic-components-textpicker.md#textpickeroptions). 30 31| Name| Type| Mandatory| Description| 32| -------- | -------- | -------- | -------- | 33| defaultPickerItemHeight | number \| string | No| Height of the picker item.| 34| disappearTextStyle<sup>10+</sup> | [PickerTextStyle](ts-basic-components-datepicker.md#pickertextstyle10) | No| Font color, font size, and font width for the top and bottom items.<br>Default value:<br>{<br>color: '#ff182431',<br>font: {<br>size: '14fp', <br>weight: FontWeight.Regular<br>}<br>} | 35| textStyle<sup>10+</sup> | [PickerTextStyle](ts-basic-components-datepicker.md#pickertextstyle10) | No| Font color, font size, and font width of all items except the top, bottom, and selected items.<br>Default value:<br>{<br>color: '#ff182431',<br>font: {<br>size: '16fp', <br>weight: FontWeight.Regular<br>}<br>} | 36| selectedTextStyle<sup>10+</sup> | [PickerTextStyle](ts-basic-components-datepicker.md#pickertextstyle10) | No| Font color, font size, and font width of the selected item.<br>Default value:<br>{<br>color: '#ff007dff',<br>font: {<br>size: '20vp', <br>weight: FontWeight.Medium<br>}<br>} | 37| canLoop<sup>10+</sup> | boolean | No| Whether to support scroll looping. The value **true** means to support scroll looping, and **false** means the opposite.<br>Default value: **true**| 38| alignment<sup>10+</sup> | [DialogAlignment](ts-methods-alert-dialog-box.md#dialogalignment) | No | Alignment mode of the dialog box in the vertical direction.<br>Default value: **DialogAlignment.Default**| 39| offset<sup>10+</sup> | [Offset](ts-types.md#offset) | No | Offset of the dialog box based on the **alignment** settings.<br>Default value: **{ dx: 0 , dy: 0 }**| 40| maskRect<sup>10+</sup>| [Rectangle](ts-methods-alert-dialog-box.md#rectangle8) | No | Mask area of the dialog box. Events outside the mask area are transparently transmitted, and events within the mask area are not.<br>Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**| 41| onAccept | (value: [TextPickerResult](#textpickerresult)) => void | No| Callback invoked when the OK button in the dialog box is clicked.| 42| onCancel | () => void | No| Callback invoked when the Cancel button in the dialog box is clicked.| 43| onChange | (value: [TextPickerResult](#textpickerresult)) => void | No| Callback invoked when the selected item changes.| 44| backgroundColor<sup>11+</sup> | [ResourceColor](ts-types.md#resourcecolor) | No| Backplane color of the dialog box.<br>Default value: **Color.Transparent**| 45| backgroundBlurStyle<sup>11+</sup> | [BlurStyle](ts-appendix-enums.md#blurstyle9) | No| Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**| 46 47## TextPickerResult 48 49| Name| Type| Description| 50| -------- | -------- | -------- | 51| value | string \| string []<sup>10+</sup> | Text of the selected item.<br>**NOTE**<br>When the picker contains text only or both text and imagery, **value** indicates the text value of the selected item. (For a multi-column picker, **value** is of the array type.)<br>For an image list, **value** is empty.| 52| index | number \| number []<sup>10+</sup> | Index of the selected item in the range. (For a multi-column picker, **index** is of the array type.)| 53 54## Example 55 56```ts 57// xxx.ets 58@Entry 59@Component 60struct TextPickerDialogExample { 61 private select: number | number[] = 0 62 private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4', 'banana5'] 63 @State v:string = ''; 64 65 build() { 66 Row() { 67 Column() { 68 Button("TextPickerDialog:" + this.v) 69 .margin(20) 70 .onClick(() => { 71 TextPickerDialog.show({ 72 range: this.fruits, 73 selected: this.select, 74 disappearTextStyle: {color: Color.Red, font: {size: 15, weight: FontWeight.Lighter}}, 75 textStyle: {color: Color.Black, font: {size: 20, weight: FontWeight.Normal}}, 76 selectedTextStyle: {color: Color.Blue, font: {size: 30, weight: FontWeight.Bolder}}, 77 onAccept: (value: TextPickerResult) => { 78 // Set select to the index of the item selected when the OK button is touched. In this way, when the text picker dialog box is displayed again, the selected item is the one last confirmed. 79 this.select = value.index 80 console.log(this.select + '') 81 // After OK is clicked, the selected item is displayed on the page. 82 this.v = value.value as string 83 console.info("TextPickerDialog:onAccept()" + JSON.stringify(value)) 84 }, 85 onCancel: () => { 86 console.info("TextPickerDialog:onCancel()") 87 }, 88 onChange: (value: TextPickerResult) => { 89 console.info("TextPickerDialog:onChange()" + JSON.stringify(value)) 90 } 91 }) 92 }) 93 }.width('100%') 94 }.height('100%') 95 } 96} 97``` 98 99 100