1e41f4b71Sopenharmony_ci# TextInput 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **TextInput** component provides single-line text input. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciNot supported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## APIs 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciTextInput(value?: TextInputOptions) 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Parameters** 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 26e41f4b71Sopenharmony_ci| ----- | ----- | ---- | ---- | 27e41f4b71Sopenharmony_ci| value | [TextInputOptions](#textinputoptions) | No | Parameters of the **TextInput** component.| 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci## TextInputOptions 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci| Name| Type | Mandatory | Description| 36e41f4b71Sopenharmony_ci| ---- | ----- | ---- | ---- | 37e41f4b71Sopenharmony_ci| placeholder | [ResourceStr](ts-types.md#resourcestr) | No | Text displayed when there is no input. | 38e41f4b71Sopenharmony_ci| text | [ResourceStr](ts-types.md#resourcestr) | No | Current text input.<br>You are advised to bind the state variable to the text in real time through the **onChange** event,<br>so as to prevent display errors when the component is updated.<br>Since API version 10, this parameter supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).| 39e41f4b71Sopenharmony_ci| controller<sup>8+</sup> | [TextInputController](#textinputcontroller8) | No | Text input controller. | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci## Attributes 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ciAmong the [universal attributes](ts-universal-attributes-size.md) and [universal text attributes](ts-universal-attributes-text-style.md), **fontColor**, **fontSize**, **fontStyle**, **fontWeight**, and **fontFamily** are supported. In addition, the following attributes are supported. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci> **NOTE** 46e41f4b71Sopenharmony_ci> When no underline is set, the default value of the universal attribute [padding](ts-universal-attributes-size.md#padding) is as follows:<br>{<br> top: '8vp',<br> right: '16vp',<br> bottom: '8vp',<br> left: '16vp'<br> } 47e41f4b71Sopenharmony_ci> 48e41f4b71Sopenharmony_ci> When an underline is set, the default value of **padding** is as follows:<br>{<br> top: '12vp',<br> right: '0vp',<br> bottom: '12vp',<br> left: '0vp'<br> } 49e41f4b71Sopenharmony_ci> 50e41f4b71Sopenharmony_ci> Since API version 10, **.width('auto')** can be set for the **TextInput** component. Under this setting, the component auto-adapts its width to the text width, while respecting the **constraintSize** configuration and the maximum and minimum width restrictions received by the parent container. For details, see [Size](ts-universal-attributes-size.md). 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci### type 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_citype(value: InputType) 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciSets the text box type. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**Parameters** 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 65e41f4b71Sopenharmony_ci| ------ | ------------------------------- | ---- | ----------------------------------------- | 66e41f4b71Sopenharmony_ci| value | [InputType](#inputtype) | Yes | Text box type.<br>Default value: **InputType.Normal**| 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci### contentType<sup>12+</sup> 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_cicontentType(value: ContentType) 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciSets the content type for autofill. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**Parameters** 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 81e41f4b71Sopenharmony_ci| ------ | ------------------------------------- | ---- | -------------- | 82e41f4b71Sopenharmony_ci| value | [ContentType](#contenttype12) | Yes | Content type for autofill.| 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci### placeholderColor 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ciplaceholderColor(value: ResourceColor) 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ciSets the placeholder text color. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**Parameters** 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 97e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------------- | 98e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Placeholder text color.<br>The default value follows the theme.| 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci### placeholderFont 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ciplaceholderFont(value?: Font) 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ciSets the placeholder text style, including the font size, font width, font family, and font style. Currently, only the default font family is supported. 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**Parameters** 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 113e41f4b71Sopenharmony_ci| ------ | ------------------------ | ---- | --------------------- | 114e41f4b71Sopenharmony_ci| value | [Font](ts-types.md#font) | No | Placeholder text style.| 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci### enterKeyType 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_cienterKeyType(value: EnterKeyType) 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ciSets the type of the Enter key. 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Parameters** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 129e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------ | ---- | ------------------------------------------------ | 130e41f4b71Sopenharmony_ci| value | [EnterKeyType](ts-types.md#enterkeytype) | Yes | Type of the Enter key.<br>Default value: **EnterKeyType.Done**| 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci### caretColor 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_cicaretColor(value: ResourceColor) 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ciSets the color of the caret in the text box. 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**Parameters** 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 145e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------- | 146e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Color of the caret in the text box.<br>Default value: **'#007DFF'**| 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci> **NOTE** 149e41f4b71Sopenharmony_ci> Since API version 12, this API can be used to set the text handle color, which is the same as the caret color. 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci### maxLength 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_cimaxLength(value: number) 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ciSets the maximum number of characters for text input. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**Parameters** 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 164e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ | 165e41f4b71Sopenharmony_ci| value | number | Yes | Maximum number of characters for text input.<br>Default value: **Infinity**, indicating that there is no maximum number.<br>**NOTE**<br>If this attribute is not set or is set to an invalid value, the default value is used. If a decimal number is specified, the integer part is used.| 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci### inputFilter<sup>8+</sup> 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ciinputFilter(value: ResourceStr, error?: (value: string) => void) 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ciSets the regular expression for input filtering. Only inputs that comply with the regular expression can be displayed. Other inputs are filtered out. The specified regular expression can match single characters, but not strings. 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ciSince API version 11, if **inputFilter** is set and the entered characters are not null, the filtering effect attached to the text box type (specified through the **type** attribute) does not take effect. 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**Parameters** 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 182e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | ---------------------------------- | 183e41f4b71Sopenharmony_ci| value | [ResourceStr](ts-types.md#resourcestr) | Yes | Regular expression. | 184e41f4b71Sopenharmony_ci| error | (value: string) => void | No | Filtered-out content to return when regular expression matching fails.| 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci### copyOption<sup>9+</sup> 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_cicopyOption(value: CopyOptions) 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ciSets whether copy and paste is allowed. If this attribute is set to **CopyOptions.None**, the paste operation is allowed, but not the copy or cut operation. 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ciFor dragging, **copyOption** only restricts whether text is selected and does not involve the dragging scope. 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**Parameters** 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 201e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 202e41f4b71Sopenharmony_ci| value | [CopyOptions](ts-appendix-enums.md#copyoptions9) | Yes | Whether copy and paste is allowed.<br>Default value: **CopyOptions.LocalDevice**| 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci### showPasswordIcon<sup>9+</sup> 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_cishowPasswordIcon(value: boolean) 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ciSets whether to display the password icon at the end of the password text box. 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci**Parameters** 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 217e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ----------------------------------------------------------- | 218e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to display the password icon at the end of the password text box.<br>Default value: **true**| 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci### style<sup>9+</sup> 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_cistyle(value: TextInputStyle | TextContentStyle) 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ciSets the text input style. The inline input style only supports **InputType.Normal**. 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**Parameters** 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 233e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 234e41f4b71Sopenharmony_ci| value | [TextInputStyle](#textinputstyle9) \| [TextContentStyle](ts-appendix-enums.md#textcontentstyle10) | Yes | Text input style.<br>Default value: **TextInputStyle.Default**| 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci### textAlign<sup>9+</sup> 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_citextAlign(value: TextAlign) 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ciSets the horizontal alignment of the text. 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ciAvailable options are **TextAlign.Start**, **TextAlign.Center**, and **TextAlign.End**. 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ciTo set vertical alignment for the text, use the [align](ts-universal-attributes-location.md) attribute. The **align** attribute alone does not control the horizontal position of the text. In other words, **Alignment.TopStart**, **Alignment.Top**, and **Alignment.TopEnd** produce the same effect, top-aligning the text; **Alignment.Start**, **Alignment.Center**, and **Alignment.End** produce the same effect, centered-aligning the text vertically; **Alignment.BottomStart**, **Alignment.Bottom**, and **Alignment.BottomEnd** produce the same effect, bottom-aligning the text. 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**Parameters** 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 253e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ---------------------------------------------------------- | 254e41f4b71Sopenharmony_ci| value | [TextAlign](ts-appendix-enums.md#textalign) | Yes | Horizontal alignment of the text.<br>Default value: **TextAlign.Start**| 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci### selectedBackgroundColor<sup>10+</sup> 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ciselectedBackgroundColor(value: ResourceColor) 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ciSets the background color of the selected text. If the opacity is not set, a 20% opacity will be used. 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**Parameters** 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 269e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------ | 270e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Background color of the selected text.<br>By default, a 20% opacity is applied.| 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci### caretStyle<sup>10+</sup> 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_cicaretStyle(value: CaretStyle) 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ciSets the caret style. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**Parameters** 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 285e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ------------ | 286e41f4b71Sopenharmony_ci| value | [CaretStyle](ts-text-common.md#caretstyle10) | Yes | Caret style.| 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci### caretPosition<sup>10+</sup> 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_cicaretPosition(value: number) 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ciSets the caret position. 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**Parameters** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 301e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------ | 302e41f4b71Sopenharmony_ci| value | number | Yes | Caret position.| 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci### showUnit<sup>10+</sup> 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_cishowUnit(value: CustomBuilder) 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ciSets the unit for content in the component. This attribute takes effect only when [showUnderline](#showunderline10) is set to **true**. 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**Parameters** 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 317e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------------ | 318e41f4b71Sopenharmony_ci| value | [CustomBuilder](ts-types.md#custombuilder8) | Yes | Unit to display as content in the text input.| 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci### showError<sup>10+</sup> 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_cishowError(value?: ResourceStr | undefined) 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ciSets the error message displayed when an error occurs. 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ciIf the data type is **ResourceStr** and the input content does not comply with specifications, the error message is displayed. If the error message does not fit in one line, an ellipsis (…) is displayed to represent clipped text. If the data type is **undefined**, no error message is displayed. See [Example 2](#example-2). 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci**Parameters** 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 335e41f4b71Sopenharmony_ci| ------ | ----------------------------- | ---- | ------------------------------------------------------------ | 336e41f4b71Sopenharmony_ci| value | [ResourceStr](ts-types.md#resourcestr) \| undefined | No | Error message displayed when an error occurs.<br>By default, no error message is displayed.<br>**NOTE**<br>The Resource type is supported since API version 12.| 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci### showUnderline<sup>10+</sup> 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_cishowUnderline(value: boolean) 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ciSets whether to show an underline. By default, the underline comes in the color of **'#33182431'**, thickness of 1 px, and text box size of 48 vp. The underline is only available for the **InputType.Normal** type. 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci**Parameters** 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 351e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------- | 352e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to show an underline.<br>Default value: **false**| 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci### underlineColor<sup>12+</sup> 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ciunderlineColor(value: ResourceColor|UnderlineColor|undefined) 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ciSets the color of the underline when it is shown. 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 365e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 366e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) \| [UnderlineColor](#underlinecolor12) \| undefined | Yes | Color of the underline.<br>The underline color changes with the underline mode. If the underline color is only set for the normal state, you can directly enter a value of the ResourceColor type. If the value specified is **undefined**, **null**, or invalid, all underlines are restored to the default value.<br>Default value: underline color configured for the theme, which is **#33182431** by default| 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci### passwordIcon<sup>10+</sup> 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_cipasswordIcon(value: PasswordIcon) 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ciSets the password icon to display at the end of the password text box. 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci**Parameters** 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 381e41f4b71Sopenharmony_ci| ------ | --------------------------------------- | ---- | ------------------------------------------------------------ | 382e41f4b71Sopenharmony_ci| value | [PasswordIcon](#passwordicon10) | Yes | Password icon to display at the end of the password text box.<br>By default, the system-provided icon is used.| 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci### enableKeyboardOnFocus<sup>10+</sup> 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_cienableKeyboardOnFocus(value: boolean) 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ciSets whether to enable the input method when the component obtains focus in a way other than clicking. 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci**Parameters** 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 399e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ----------------------------------------------------------- | 400e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to enable the input method when the component obtains focus in a way other than clicking.<br>Default value: **true**| 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci### selectionMenuHidden<sup>10+</sup> 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ciselectionMenuHidden(value: boolean) 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ciSets whether to hide the text selection menu when the text box is long-pressed, double-touched, or right-clicked. 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**Parameters** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 415e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 416e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to hide the text selection menu when the text box is long-pressed, double-touched, or right-clicked.<br>Default value: **false**| 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci### barState<sup>10+</sup> 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_cibarState(value: BarState) 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ciSets the scrollbar state when the inline input style is used. 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**Parameters** 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 431e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 432e41f4b71Sopenharmony_ci| value | [BarState](ts-appendix-enums.md#barstate) | Yes | Scrollbar state when the inline input style is used.<br>Default value: **BarState.Auto**| 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci### maxLines<sup>10+</sup> 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_cimaxLines(value: number) 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ciSets the maximum number of lines that can be displayed when the inline input style is used. 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci**Parameters** 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 447e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 448e41f4b71Sopenharmony_ci| value | number | Yes | Maximum number of lines that can be displayed with the inline style in the editing state or with the non-inline style.<br>Default value: **3**<br>Value range: (0, +∞)| 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci### customKeyboard<sup>10+</sup> 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_cicustomKeyboard(value: CustomBuilder, options?: KeyboardOptions) 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ciSets a custom keyboard. 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ciWhen a custom keyboard is set, activating the text box opens the specified custom component, instead of the system input method. 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ciThe custom keyboard's height can be set through the **height** attribute of the custom component's root node, and its width is fixed at the default value. 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ciThe custom keyboard is displayed on top of the current page, without compressing or raising the page. 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ciThe custom keyboard cannot obtain the focus, but it blocks gesture events. 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ciBy default, the custom keyboard is closed when the input component loses the focus. You can also use the [TextInputController](#textinputcontroller8).[stopEditing](#stopediting10) API to close the keyboard. 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ciWhen a custom keyboard is set, the text box does not support camera input, even when the device supports. 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci**Parameters** 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 475e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 476e41f4b71Sopenharmony_ci| value | [CustomBuilder](ts-types.md#custombuilder8) | Yes | Custom keyboard.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 477e41f4b71Sopenharmony_ci| options<sup>12+</sup> | [KeyboardOptions](ts-basic-components-richeditor.md#keyboardoptions12) | No | Whether to support keyboard avoidance. | 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci### enableAutoFill<sup>11+</sup> 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_cienableAutoFill(value: boolean) 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ciSets whether to enable autofill. 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci**Parameters** 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 492e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 493e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to enable autofill.<br>**true**: enable<br>**false**: disable<br><br>Default value: **true**| 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci### passwordRules<sup>11+</sup> 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_cipasswordRules(value: string) 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciRules for generating passwords. When autofill is used, these rules are transparently transmitted to Password Vault for generating a new password. 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**Parameters** 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 508e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- | 509e41f4b71Sopenharmony_ci| value | string | Yes | Rules for generating passwords.| 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci### cancelButton<sup>11+</sup> 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_cicancelButton(value: { style?: CancelButtonStyle, icon?: IconOptions }) 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ciSets the style of the Cancel button on the right. This attribute is not available for the inline input style. 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci**Parameters** 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 524e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 525e41f4b71Sopenharmony_ci| value | {<br>style? : [CancelButtonStyle](ts-basic-components-search.md#cancelbuttonstyle10)<br>icon?: [IconOptions](ts-basic-components-search.md#iconoptions10) <br>} | Yes | Style of the Cancel button on the right.<br>Default value:<br>{<br>style: CancelButtonStyle.INPUT<br>} | 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci### selectAll<sup>11+</sup> 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ciselectAll(value: boolean) 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ciSets whether to select all text in the initial state. This attribute is not available for the inline input style. 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci**Parameters** 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 540e41f4b71Sopenharmony_ci| ------ | ------- | ---- | --------------------------------- | 541e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to select all text in the initial state.<br>Default value: **false**| 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci### showCounter<sup>11+</sup> 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_cishowCounter(value: boolean, options?: InputCounterOptions) 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ciSets the character counter displayed when the number of characters entered exceeds the threshold. 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci**options** can be set only when **value** is set to **true**, in which case a character counter is displayed below the text box. This attribute must be used together with **maxLength**. The character counter is displayed in this format: Number of characters entered/Character limit. 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ciIt is visible when the number of characters entered is greater than the character limit multiplied by the threshold percentage value. If **options** is not set, the text box border and character counter subscript turn red when the number of characters entered exceeds the limit. If **value** is set to **true** and **options** is set, the text box border and character counter subscript turn red and the text box shakes when the number of characters entered reaches the limit, provided that the value of **thresholdPercentage** is valid. If **highlightBorder** is set to **false**, the text box border does not turn red. By default, **highlightBorder** is set to **true**. 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ciThe character counter is not displayed for text boxes in inline or password input style. 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci**Parameters** 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 562e41f4b71Sopenharmony_ci| --------------------- | ----------------------------------------------------- | ---- | ---------------- | 563e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to display the character counter.| 564e41f4b71Sopenharmony_ci| options<sup>11+</sup> | [InputCounterOptions](ts-types.md#inputcounteroptions11) | No | Threshold percentage of the character counter.| 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ci### lineHeight<sup>12+</sup> 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_cilineHeight(value: number | string | Resource) 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ciSets the text line height. If the value is less than or equal to **0**, the line height is not limited and the font size is adaptive. If the value is of the number type, the unit fp is used. 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci**Parameters** 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 579e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ---------------- | 580e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Text line height.| 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci### decoration<sup>12+</sup> 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_cidecoration(value: TextDecorationOptions) 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ciSets the color, type, and style of the text decorative line. This attribute does not take effect for the password input mode. 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ci**Parameters** 593e41f4b71Sopenharmony_ci 594e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 595e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 596e41f4b71Sopenharmony_ci| value | [TextDecorationOptions](ts-types.md#textdecorationoptions12) | Yes | Text decorative line options.<br>Default value: {<br> type: TextDecorationType.None,<br> color: Color.Black,<br> style: TextDecorationStyle.SOLID <br>} | 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci### letterSpacing<sup>12+</sup> 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ciletterSpacing(value: number | string | Resource) 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ciSets the letter spacing for a text style. If the value specified is a percentage or 0, the default value is used. 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ciIf the value specified is a negative value, the text is compressed. A negative value too small may result in the text being compressed to 0 and no content being displayed. 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci**Parameters** 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 613e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | -------------- | 614e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Letter spacing.| 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci### fontFeature<sup>12+</sup> 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_cifontFeature(value: string) 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ciSets the font feature, for example, monospaced digits. 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ciFormat: normal \| \<feature-tag-value\> 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ciFormat of **\<feature-tag-value\>**: \<string\> \[ \<integer\> \| on \| off ] 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ciThere can be multiple **\<feature-tag-value\>** values, which are separated by commas (,). 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ciFor example, the input format for monospaced clock fonts is "ss01" on. 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci**Parameters** 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 637e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- | 638e41f4b71Sopenharmony_ci| value | string | Yes | Font feature.| 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ciFor details about the supported font features, see [Font Feature List](ts-basic-components-text.md#fontfeature12). 641e41f4b71Sopenharmony_ciFont features are advanced typographic features, such as ligatures and monospace, for OpenType fonts. They are typically used in custom fonts and require the support of the font itself. 642e41f4b71Sopenharmony_ciFor more information about the font features, see [Low-level font feature settings control: the font-feature-settings property](https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop) and [The Complete CSS Demo for OpenType Features](https://sparanoid.com/lab/opentype-features/). 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci> **NOTE** 645e41f4b71Sopenharmony_ci> This attribute is not available when **type** is set to an enum value that indicates the password input mode, such as Password, **NEW_PASSWORD**, or **NUMBER_PASSWORD**. 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ci### wordBreak<sup>12+</sup> 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ciwordBreak(value: WordBreak) 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ciSets the word break rule. This attribute is effective for the inline input style, but does not apply to the placeholder text. 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci**Parameters** 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 660e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 661e41f4b71Sopenharmony_ci| value | [WordBreak](ts-appendix-enums.md#wordbreak11) | Yes | Word break rule in the inline input style.<br>Default value: **WordBreak.BREAK_WORD**| 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci> **NOTE** 664e41f4b71Sopenharmony_ci> 665e41f4b71Sopenharmony_ci> The component does not support the **clip** attribute. Therefore, setting this attribute does not affect text clipping. 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci### textOverflow<sup>12+</sup> 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_citextOverflow(value: TextOverflow) 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ciSets the display mode when the text is too long. This attribute is only available for the inline input style. 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ciText is clipped at the transition between words. To clip text in the middle of a word, set **wordBreak** to **WordBreak.BREAK_ALL**. 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci**TextOverflow.None** produces the same effect as **TextOverflow.Clip**. 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci**Parameters** 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 684e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------------------------------------------------------------------------------- | 685e41f4b71Sopenharmony_ci| value | [TextOverflow](ts-appendix-enums.md#textoverflow) | Yes | Display mode when the text is too long.<br>Default value in non-editing state in the inline input style: **TextOverflow.Ellipsis**<br>Default value in editing state in the inline input style: **TextOverflow.Clip** | 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci> **NOTE** 688e41f4b71Sopenharmony_ci> The **TextInput** component does not support the **TextOverflow.MARQUEE** mode. If this attribute is set to **TextOverflow.MARQUEE**, **TextOverflow.Ellipsis** is used instead for the non-editing state in the inline input style and **TextOverflow.Clip** for the non-inline input style and the editing state in the inline input style. 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ci### textIndent<sup>12+</sup> 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_citextIndent(value: Dimension) 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_ciSets the indent of the first line text. 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci**Parameters** 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 703e41f4b71Sopenharmony_ci| ------ | ------------------------------------ | ---- | ---------------------------- | 704e41f4b71Sopenharmony_ci| value | [Dimension](ts-types.md#dimension10) | Yes | Indent of the first line text.<br>Default value: **0**| 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ci### minFontSize<sup>12+</sup> 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ciminFontSize(value: number | string | Resource) 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_ciSets the minimum font size. 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ciFor the setting to take effect, this attribute must be used together with [maxFontSize](#maxfontsize12) and [maxLines](#maxlines10) (when the component is in editing state in the inline input style), or layout constraint settings. 713e41f4b71Sopenharmony_ci 714e41f4b71Sopenharmony_ciWhen the adaptive font size is used, the **fontSize** settings do not take effect. 715e41f4b71Sopenharmony_ci 716e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci**Parameters** 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 723e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 724e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Minimum font size.| 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci### maxFontSize<sup>12+</sup> 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_cimaxFontSize(value: number | string | Resource) 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ciSets the maximum font size. 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ciFor the setting to take effect, this attribute must be used together with [minFontSize](#minfontsize12) and [maxLines](#maxlines10) (when the component is in editing state in the inline input style), or layout constraint settings. 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ciWhen the adaptive font size is used, the **fontSize** settings do not take effect. 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ci**Parameters** 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 743e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 744e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Maximum font size.| 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ci### heightAdaptivePolicy<sup>12+</sup> 747e41f4b71Sopenharmony_ci 748e41f4b71Sopenharmony_ciheightAdaptivePolicy(value: TextHeightAdaptivePolicy) 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ciSets how the adaptive height is determined for the text in the inline input style. 751e41f4b71Sopenharmony_ci 752e41f4b71Sopenharmony_ciWhen this attribute is set to **TextHeightAdaptivePolicy.MAX_LINES_FIRST**, the [maxLines](#maxlines10) attribute takes precedence for adjusting the text height. If the **maxLines** setting results in a layout beyond the layout constraints, the text will shrink to a font size between [minFontSize](#minfontsize12) and [maxFontSize](#maxfontsize12) to allow for more content to be shown. 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ciIf this attribute is set to **TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST**, the **minFontSize** attribute takes precedence for adjusting the text height. If the text can fit in one line with the **minFontSize** setting, the text will enlarge to the largest possible font size between **minFontSize** and **maxFontSize**. 755e41f4b71Sopenharmony_ci 756e41f4b71Sopenharmony_ci**TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST** produces the same effect as **TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST**. 757e41f4b71Sopenharmony_ci 758e41f4b71Sopenharmony_ciWhen the component is in the non-inline input style, the three values of **TextHeightAdaptivePolicy** have the same effect, that is, the text will shrink to a font size between **minFontSize** and **maxFontSize** to allow for more content to be shown. 759e41f4b71Sopenharmony_ci 760e41f4b71Sopenharmony_ci> **NOTE** 761e41f4b71Sopenharmony_ci> 762e41f4b71Sopenharmony_ci> If the text box is in inline input style, the font size in the editing state is different from that in the non-editing state. 763e41f4b71Sopenharmony_ci 764e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 765e41f4b71Sopenharmony_ci 766e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci**Parameters** 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 771e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 772e41f4b71Sopenharmony_ci| value | [TextHeightAdaptivePolicy](ts-appendix-enums.md#textheightadaptivepolicy10) | Yes | How the adaptive height is determined for the text.<br>Default value: **TextHeightAdaptivePolicy.MAX_LINES_FIRST**| 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ci### showPassword<sup>12+</sup> 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_cishowPassword(visible: boolean) 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ciSets whether to show the password. 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ciThis attribute takes effect only in password input mode. 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ciAs the password icon has a built-in state for updating the password mode, you are advised to add state synchronization to [onSecurityStateChange](#onsecuritystatechange12). 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 785e41f4b71Sopenharmony_ci 786e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci**Parameters** 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 791e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 792e41f4b71Sopenharmony_ci| visible | boolean | Yes | Whether to show the password.<br>Default value: **false**| 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci### lineBreakStrategy<sup>12+</sup> 795e41f4b71Sopenharmony_ci 796e41f4b71Sopenharmony_cilineBreakStrategy(strategy: LineBreakStrategy) 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ciSets the line break rule. This attribute takes effect when **wordBreak** is not set to **breakAll**. Hyphens are not supported. 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_ci**Parameters** 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 807e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 808e41f4b71Sopenharmony_ci| strategy | [LineBreakStrategy](ts-appendix-enums.md#linebreakstrategy12) | Yes | Line break rule.<br>Default value: **LineBreakStrategy.GREEDY**<br>**NOTE**<br> This attribute does not take effect for the non-inline input style.| 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci### editMenuOptions<sup>12+</sup> 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_cieditMenuOptions(editMenu: EditMenuOptions) 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ciSets the extended options of the custom context menu on selection, including the text content, icon, and callback. 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci**Parameters** 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 823e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 824e41f4b71Sopenharmony_ci| editMenu | [EditMenuOptions](ts-text-common.md#editmenuoptions) | Yes | Extended options of the custom context menu on selection.| 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_ci### enablePreviewText<sup>12+</sup> 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_cienablePreviewText(enable: boolean) 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ciSets whether to enable preview text. 831e41f4b71Sopenharmony_ci 832e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ci**Parameters** 837e41f4b71Sopenharmony_ci 838e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 839e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------- | 840e41f4b71Sopenharmony_ci| enable | boolean | Yes | Whether to enable preview text.<br>Default value: **true**| 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci## InputType 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 845e41f4b71Sopenharmony_ci 846e41f4b71Sopenharmony_ci| Name | Description | 847e41f4b71Sopenharmony_ci| ----------------------------- | ------------------------------------------------------------ | 848e41f4b71Sopenharmony_ci| Normal | Normal input mode. In this mode, there is no special restriction on the input characters.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 849e41f4b71Sopenharmony_ci| Password | Password input mode.<br>The value can contain digits, letters, underscores (_), spaces, and special characters. An eye icon is used to show or hide the password. By default, the entered characters are temporarily shown before being obscured by dots; they are directly obscured by dots since API version 12 on certain devices. The password input mode does not support underlines. If Password Vault is enabled, autofill is available for the username and password.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 850e41f4b71Sopenharmony_ci| Email | Email address input mode.<br>This mode accepts only digits, letters, underscores (_), dots (.), and the following special characters: ! # $ % & ' * + - / = ? ^ ` \{ \| \} ~ @ (which can only appear once)<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 851e41f4b71Sopenharmony_ci| Number | Digit input mode.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 852e41f4b71Sopenharmony_ci| PhoneNumber<sup>9+</sup> | Phone number input mode.<br>In this mode, the following are allowed: digits, spaces, plus signs (+), hyphens (-), asterisks (*), and number signs (#); the length is not limited.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 853e41f4b71Sopenharmony_ci| USER_NAME<sup>11+</sup> | Username input mode.<br>If Password Vault is enabled, autofill is available for the username and password.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 854e41f4b71Sopenharmony_ci| NEW_PASSWORD<sup>11+</sup> | New password input mode.<br>An eye icon is used to show or hide the password. By default, the entered characters are temporarily shown before being obscured by dots; they are directly obscured by dots since API version 12 on certain devices. If Password Vault is enabled, a new password can be automatically generated.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 855e41f4b71Sopenharmony_ci| NUMBER_PASSWORD<sup>11+</sup> | Numeric password input mode.<br>An eye icon is used to show or hide the password. By default, the entered characters are temporarily shown before being obscured by dots; they are directly obscured by dots since API version 12 on certain devices. The password input mode does not support underlines.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 856e41f4b71Sopenharmony_ci| NUMBER_DECIMAL<sup>11+</sup> | Number input mode with a decimal point.<br>The value can contain digits and one decimal point.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 857e41f4b71Sopenharmony_ci| URL<sup>12+</sup> | URL input mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci## ContentType<sup>12+</sup> 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ciContent type for autofill. 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 864e41f4b71Sopenharmony_ci 865e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_ci| Name | Value | Description | 868e41f4b71Sopenharmony_ci| -------------------------- | ---- | ------------------------------------------------------------ | 869e41f4b71Sopenharmony_ci| USER_NAME | 0 | Username. Password Vault, when enabled, can automatically save and fill in usernames.| 870e41f4b71Sopenharmony_ci| PASSWORD | 1 | Password. Password Vault, when enabled, can automatically save and fill in passwords.| 871e41f4b71Sopenharmony_ci| NEW_PASSWORD | 2 | New password. Password Vault, when enabled, can automatically generate a new password. | 872e41f4b71Sopenharmony_ci| FULL_STREET_ADDRESS | 3 | Full street address. The scenario-based autofill feature, when enabled, can automatically save and fill in full street addresses.| 873e41f4b71Sopenharmony_ci| HOUSE_NUMBER | 4 | House number. The scenario-based autofill feature, when enabled, can automatically save and fill in house numbers.| 874e41f4b71Sopenharmony_ci| DISTRICT_ADDRESS | 5 | District and county. The scenario-based autofill feature, when enabled, can automatically save and fill in districts and counties.| 875e41f4b71Sopenharmony_ci| CITY_ADDRESS | 6 | City. The scenario-based autofill feature, when enabled, can automatically save and fill in cities.| 876e41f4b71Sopenharmony_ci| PROVINCE_ADDRESS | 7 | Province. The scenario-based autofill feature, when enabled, can automatically save and fill in provinces.| 877e41f4b71Sopenharmony_ci| COUNTRY_ADDRESS | 8 | Country. The scenario-based autofill feature, when enabled, can automatically save and fill in countries.| 878e41f4b71Sopenharmony_ci| PERSON_FULL_NAME | 9 | Full name. The scenario-based autofill feature, when enabled, can automatically save and fill in full names.| 879e41f4b71Sopenharmony_ci| PERSON_LAST_NAME | 10 | Last name. The scenario-based autofill feature, when enabled, can automatically save and fill in last names.| 880e41f4b71Sopenharmony_ci| PERSON_FIRST_NAME | 11 | First name. The scenario-based autofill feature, when enabled, can automatically save and fill in first names.| 881e41f4b71Sopenharmony_ci| PHONE_NUMBER | 12 | Phone number. The scenario-based autofill feature, when enabled, can automatically save and fill in phone numbers.| 882e41f4b71Sopenharmony_ci| PHONE_COUNTRY_CODE | 13 | Country code. The scenario-based autofill feature, when enabled, can automatically save and fill in country codes.| 883e41f4b71Sopenharmony_ci| FULL_PHONE_NUMBER | 14 | Phone number with country code. The scenario-based autofill feature, when enabled, can automatically save and fill in phone numbers with country codes.| 884e41f4b71Sopenharmony_ci| EMAIL_ADDRESS | 15 | Email address. The scenario-based autofill feature, when enabled, can automatically save and fill in email addresses.| 885e41f4b71Sopenharmony_ci| BANK_CARD_NUMBER | 16 | Bank card number. The scenario-based autofill feature, when enabled, can automatically save and fill in bank card numbers.| 886e41f4b71Sopenharmony_ci| ID_CARD_NUMBER | 17 | ID card number. The scenario-based autofill feature, when enabled, can automatically save and fill in ID card numbers.| 887e41f4b71Sopenharmony_ci| NICKNAME | 23 | Nickname. The scenario-based autofill feature, when enabled, can automatically save and fill in nicknames.| 888e41f4b71Sopenharmony_ci| DETAIL_INFO_WITHOUT_STREET | 24 | Address information without street address. The scenario-based autofill feature, when enabled, can automatically save and fill in address information without street addresses.| 889e41f4b71Sopenharmony_ci| FORMAT_ADDRESS | 25 | Standard address. The scenario-based autofill feature, when enabled, can automatically save and fill in standard addresses.| 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci## TextInputStyle<sup>9+</sup> 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ci| Name | Description | 898e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 899e41f4b71Sopenharmony_ci| Default | Default style. The caret width is fixed at 1.5 vp, and the caret height is subject to the background height and font size of the selected text. | 900e41f4b71Sopenharmony_ci| Inline | Inline input style. The background height of the selected text is the same as the height of the text box.<br>This style is used in scenarios where editing and non-editing states are obvious, for example, renaming in the file list view.<br>The **showError** attribute is not supported for this style.| 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ci## PasswordIcon<sup>10+</sup> 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci| Name| Type | Mandatory | Description| 909e41f4b71Sopenharmony_ci| ---- | ----- | ---- | ---- | 910e41f4b71Sopenharmony_ci| onIconSrc | string \| [Resource](ts-types.md#resource) | No | Icon that can be used to hide the password in password input mode.| 911e41f4b71Sopenharmony_ci| offIconSrc | string \| [Resource](ts-types.md#resource) | No | Icon that can be used to show the password in password input mode.| 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci## Events 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following events are supported. 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_ci### onChange 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_cionChange(callback: EditableTextOnChangeCallback) 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ciCalled when the input in the text box changes. 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ciThis event is triggered when any of the following conditions is met: 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_ci1. Keyboard input is received. 926e41f4b71Sopenharmony_ci 927e41f4b71Sopenharmony_ci2. Paste and cut is performed. 928e41f4b71Sopenharmony_ci 929e41f4b71Sopenharmony_ci3. Ctrl+V is pressed. 930e41f4b71Sopenharmony_ci 931e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 932e41f4b71Sopenharmony_ci 933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 934e41f4b71Sopenharmony_ci 935e41f4b71Sopenharmony_ci**Parameters** 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 938e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- | 939e41f4b71Sopenharmony_ci| callback | [EditableTextOnChangeCallback](ts-text-common.md#editabletextonchangecallback12) | Yes | Callback invoked when the input in the text box changes.| 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_ci### onSubmit 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_cionSubmit(callback: (enterKey: EnterKeyType, event: SubmitEvent) => void) 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ciCalled when the Enter key on the keyboard is pressed. 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci**Parameters** 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 954e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 955e41f4b71Sopenharmony_ci| enterKey | [EnterKeyType](ts-types.md#enterkeytype) | Yes | Type of the Enter key. If it is **EnterKeyType.NEW_LINE** and the text box is in inline input style, **onSubmit** is not triggered.| 956e41f4b71Sopenharmony_ci| event<sup>11+</sup> | [SubmitEvent](#submitevent11) | Yes | Submit event. | 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci### onEditChanged<sup>(deprecated)</sup> 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_cionEditChanged(callback: (isEditing: boolean) => void) 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ciCalled when the input status changes. 963e41f4b71Sopenharmony_ci 964e41f4b71Sopenharmony_ciThis API is deprecated since API version 8. You are advised to use **onEditChange** instead. 965e41f4b71Sopenharmony_ci 966e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 967e41f4b71Sopenharmony_ci 968e41f4b71Sopenharmony_ci**Parameters** 969e41f4b71Sopenharmony_ci 970e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 971e41f4b71Sopenharmony_ci| --------- | ------- | ---- | -------------------- | 972e41f4b71Sopenharmony_ci| isEditing | boolean | Yes | Whether the text box is in the editing state. The value **true** indicates that the text box is in the editing state.| 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ci### onEditChange<sup>8+</sup> 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_cionEditChange(callback: (isEditing: boolean) => void) 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ciCalled when the input status changes. The text box is in the editing state when it has the caret placed in it, and is in the non-editing state otherwise. If the value of **isEditing** is **true**, the text box is in the editing state. 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci**Parameters** 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 987e41f4b71Sopenharmony_ci| --------- | ------- | ---- | -------------------- | 988e41f4b71Sopenharmony_ci| isEditing | boolean | Yes | Whether the text box is in the editing state. The value **true** indicates that the text box is in the editing state.| 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci### onCopy<sup>8+</sup> 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_cionCopy(callback: (value: string) => void) 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ciCalled when the copy button on the pasteboard, which displays when the text box is long pressed, is clicked. 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 999e41f4b71Sopenharmony_ci 1000e41f4b71Sopenharmony_ci**Parameters** 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1003e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ---------------- | 1004e41f4b71Sopenharmony_ci| value | string | Yes | Text that is copied.| 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci### onCut<sup>8+</sup> 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_cionCut(callback: (value: string) => void) 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ciCalled when the cut button on the pasteboard, which displays when the text box is long pressed, is clicked. 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1013e41f4b71Sopenharmony_ci 1014e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1015e41f4b71Sopenharmony_ci 1016e41f4b71Sopenharmony_ci**Parameters** 1017e41f4b71Sopenharmony_ci 1018e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1019e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ---------------- | 1020e41f4b71Sopenharmony_ci| value | string | Yes | Text that is cut.| 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci### onPaste<sup>8+</sup> 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_cionPaste(callback: (value: string, event: PasteEvent) => void) 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_ciCalled when the paste button on the pasteboard, which displays when the text box is long pressed, is clicked. 1027e41f4b71Sopenharmony_ci 1028e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ci**Parameters** 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1035e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------------------ | ---- | ---------------------- | 1036e41f4b71Sopenharmony_ci| value | string | Yes | Text to be pasted. | 1037e41f4b71Sopenharmony_ci| event<sup>11+</sup> | [PasteEvent](ts-basic-components-richeditor.md#pasteevent11) | No | Custom paste event.| 1038e41f4b71Sopenharmony_ci 1039e41f4b71Sopenharmony_ci### onTextSelectionChange<sup>10+</sup> 1040e41f4b71Sopenharmony_ci 1041e41f4b71Sopenharmony_cionTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void) 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ciCalled when the position of the text selection changes or when the cursor position changes during the editing state. 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_ci**Parameters** 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1052e41f4b71Sopenharmony_ci| -------------- | ------ | ---- | --------------------------------------- | 1053e41f4b71Sopenharmony_ci| selectionStart | number | Yes | Start position of the selected text. The start position of text is **0**.| 1054e41f4b71Sopenharmony_ci| selectionEnd | number | Yes | End position of the selected text. | 1055e41f4b71Sopenharmony_ci 1056e41f4b71Sopenharmony_ci### onContentScroll<sup>10+</sup> 1057e41f4b71Sopenharmony_ci 1058e41f4b71Sopenharmony_cionContentScroll(callback: (totalOffsetX: number, totalOffsetY: number) => void) 1059e41f4b71Sopenharmony_ci 1060e41f4b71Sopenharmony_ciCalled when the text content is scrolled. 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1063e41f4b71Sopenharmony_ci 1064e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1065e41f4b71Sopenharmony_ci 1066e41f4b71Sopenharmony_ci**Parameters** 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1069e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ---------------------------------- | 1070e41f4b71Sopenharmony_ci| totalOffsetX | number | Yes | Offset in the X coordinate of the text in the content area, in px.| 1071e41f4b71Sopenharmony_ci| totalOffsetY | number | Yes | Offset in the Y coordinate of the text in the content area, in px.| 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci### onSecurityStateChange<sup>12+</sup> 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_cionSecurityStateChange(callback: Callback\<boolean>) 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ciCalled when the password visibility changes. 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**Parameters** 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1086e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ---------------------------------- | 1087e41f4b71Sopenharmony_ci| callback | Callback\<boolean> | Yes | Callback used to return the result.| 1088e41f4b71Sopenharmony_ci 1089e41f4b71Sopenharmony_ci### onWillInsert<sup>12+</sup> 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_cionWillInsert(callback: Callback\<InsertValue, boolean>) 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ciCalled when text is about to be inserted. 1094e41f4b71Sopenharmony_ci 1095e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_ci**Parameters** 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1102e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 1103e41f4b71Sopenharmony_ci| callback | Callback\<[InsertValue](ts-text-common.md#insertvalue12), boolean> | Yes | Callback triggered when text is about to be inserted.<br>It returns **true** if the text is inserted; returns **false** otherwise.<br>This callback is not called for text preview.<br>It is available only for system input methods.| 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ci### onDidInsert<sup>12+</sup> 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_cionDidInsert(callback: Callback\<InsertValue>) 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_ciCalled when text is inserted. 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**Parameters** 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1118e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 1119e41f4b71Sopenharmony_ci| callback | Callback\<[InsertValue](ts-text-common.md#insertvalue12)> | Yes | Callback triggered when text is inserted.<br>It is available only for system input methods.| 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci### onWillDelete<sup>12+</sup> 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_cionWillDelete(callback: Callback\<DeleteValue, boolean>) 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ciCalled when text is about to be deleted. 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_ci**Parameters** 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1134e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 1135e41f4b71Sopenharmony_ci| callback | Callback\<[DeleteValue](ts-text-common.md#deletevalue12), boolean> | Yes | Callback triggered when text is about to be deleted.<br>It returns **true** if the text is deleted; returns **false** otherwise.<br>This callback is not called for text preview.<br>It is available only for system input methods.| 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ci### onDidDelete<sup>12+</sup> 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_cionDidDelete(callback: Callback\<DeleteValue>) 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ciCalled when text is deleted. 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_ci**Parameters** 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1150e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 1151e41f4b71Sopenharmony_ci| callback | Callback\<[DeleteValue](ts-text-common.md#deletevalue12)> | Yes | Callback triggered when text is deleted.<br>It is available only for system input methods.| 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci## TextInputController<sup>8+</sup> 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ciInherits from [TextContentControllerBase](ts-types.md#textcontentcontrollerbase10). 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1158e41f4b71Sopenharmony_ci 1159e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci### Objects to Import 1162e41f4b71Sopenharmony_ci``` 1163e41f4b71Sopenharmony_cicontroller: TextInputController = new TextInputController() 1164e41f4b71Sopenharmony_ci``` 1165e41f4b71Sopenharmony_ci 1166e41f4b71Sopenharmony_ci### constructor<sup>8+</sup> 1167e41f4b71Sopenharmony_ci 1168e41f4b71Sopenharmony_ciconstructor() 1169e41f4b71Sopenharmony_ci 1170e41f4b71Sopenharmony_ciA constructor used to create a **TextInputController** object. 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci### caretPosition<sup>8+</sup> 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_cicaretPosition(value: number): void 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_ciSets the position of the caret. 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1185e41f4b71Sopenharmony_ci 1186e41f4b71Sopenharmony_ci**Parameters** 1187e41f4b71Sopenharmony_ci 1188e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1189e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ------ | 1190e41f4b71Sopenharmony_ci| value | number | Yes | Length from the start of the string to the position where the caret is located.| 1191e41f4b71Sopenharmony_ci### setTextSelection<sup>10+</sup> 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_cisetTextSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ciSets the text selection area, which will be highlighted. 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_ci**Parameters** 1202e41f4b71Sopenharmony_ci 1203e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1204e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ----- | 1205e41f4b71Sopenharmony_ci| selectionStart | number | Yes | Start position of the text selection range. The start position of text in the text box is 0.| 1206e41f4b71Sopenharmony_ci| selectionEnd | number | Yes | End position of the text selection range.| 1207e41f4b71Sopenharmony_ci| options<sup>12+</sup> | [SelectionOptions](ts-types.md#selectionoptions12) | No | Configuration options for text selection.<br>Default value: **MenuPolicy.DEFAULT**<br>This API can be used in atomic services since API version 12.| 1208e41f4b71Sopenharmony_ci 1209e41f4b71Sopenharmony_ci> **NOTE** 1210e41f4b71Sopenharmony_ci> 1211e41f4b71Sopenharmony_ci> If **selectionStart** or **selectionEnd** is set to **undefined**, the value **0** will be used. 1212e41f4b71Sopenharmony_ci> 1213e41f4b71Sopenharmony_ci> If **selectionMenuHidden** is set to **true** or a 2-in-1 device is used, calling **setTextSelection** does not display the context menu even when **options** is set to **MenuPolicy.SHOW**. 1214e41f4b71Sopenharmony_ci> 1215e41f4b71Sopenharmony_ci> If the selected text contains an emoji, the emoji is selected when its start position is within the text selection range. 1216e41f4b71Sopenharmony_ci 1217e41f4b71Sopenharmony_ci### stopEditing<sup>10+</sup> 1218e41f4b71Sopenharmony_ci 1219e41f4b71Sopenharmony_cistopEditing(): void 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ciExits the editing state. 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1226e41f4b71Sopenharmony_ci 1227e41f4b71Sopenharmony_ci## UnderlineColor<sup>12+</sup> 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci| Name| Type | Mandatory | Description| 1234e41f4b71Sopenharmony_ci| ---- | ----- | ---- | ---- | 1235e41f4b71Sopenharmony_ci| typing | [ResourceColor](ts-types.md#resourcecolor) \| undefined | No | Underline color in the typing state. If no value is specified or if the value specified is **undefined**, **null**, or invalid, the default value is used.| 1236e41f4b71Sopenharmony_ci| normal | [ResourceColor](ts-types.md#resourcecolor) \| undefined | No | Underline color in the normal state. If no value is specified or if the value specified is **undefined**, **null**, or invalid, the default value is used.| 1237e41f4b71Sopenharmony_ci| error | [ResourceColor](ts-types.md#resourcecolor) \| undefined | No | Underline color when an error occurs. If no value is specified or if the value specified is **undefined**, **null**, or invalid, the default value is used. This option changes the color used in the **showCounter** attribute when the maximum number of characters is reached.| 1238e41f4b71Sopenharmony_ci| disable | [ResourceColor](ts-types.md#resourcecolor) \| undefined | No | Underline color in the disabled state. If no value is specified or if the value specified is **undefined**, **null**, or invalid, the default value is used.| 1239e41f4b71Sopenharmony_ci 1240e41f4b71Sopenharmony_ci## SubmitEvent<sup>11+</sup> 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_ciDefines the user submission event. 1243e41f4b71Sopenharmony_ci 1244e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1245e41f4b71Sopenharmony_ci 1246e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci| Name| Type | Mandatory | Description| 1249e41f4b71Sopenharmony_ci| ---- | ----- | ---- | ---- | 1250e41f4b71Sopenharmony_ci| keepEditableState | () => void | Yes | Editing status of the text box.<br> When this API is called, the text box remains in editing state.| 1251e41f4b71Sopenharmony_ci| text | string | Yes | Text in the text box. | 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci## Example 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_ci### Example 1 1256e41f4b71Sopenharmony_ciThis example demonstrates the basic usage of **TextInput**. 1257e41f4b71Sopenharmony_ci```ts 1258e41f4b71Sopenharmony_ci// xxx.ets 1259e41f4b71Sopenharmony_ci@Entry 1260e41f4b71Sopenharmony_ci@Component 1261e41f4b71Sopenharmony_cistruct TextInputExample { 1262e41f4b71Sopenharmony_ci @State text: string = '' 1263e41f4b71Sopenharmony_ci @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 } 1264e41f4b71Sopenharmony_ci @State passwordState: boolean = false 1265e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_ci build() { 1268e41f4b71Sopenharmony_ci Column() { 1269e41f4b71Sopenharmony_ci TextInput({ text: this.text, placeholder: 'input your word...', controller: this.controller }) 1270e41f4b71Sopenharmony_ci .placeholderColor(Color.Grey) 1271e41f4b71Sopenharmony_ci .placeholderFont({ size: 14, weight: 400 }) 1272e41f4b71Sopenharmony_ci .caretColor(Color.Blue) 1273e41f4b71Sopenharmony_ci .width('95%') 1274e41f4b71Sopenharmony_ci .height(40) 1275e41f4b71Sopenharmony_ci .margin(20) 1276e41f4b71Sopenharmony_ci .fontSize(14) 1277e41f4b71Sopenharmony_ci .fontColor(Color.Black) 1278e41f4b71Sopenharmony_ci .inputFilter('[a-z]', (e) => { 1279e41f4b71Sopenharmony_ci console.log(JSON.stringify(e)) 1280e41f4b71Sopenharmony_ci }) 1281e41f4b71Sopenharmony_ci .onChange((value: string) => { 1282e41f4b71Sopenharmony_ci this.text = value 1283e41f4b71Sopenharmony_ci }) 1284e41f4b71Sopenharmony_ci Text(this.text) 1285e41f4b71Sopenharmony_ci Button('Set caretPosition 1') 1286e41f4b71Sopenharmony_ci .margin(15) 1287e41f4b71Sopenharmony_ci .onClick(() => { 1288e41f4b71Sopenharmony_ci // Move the caret to after the first entered character. 1289e41f4b71Sopenharmony_ci this.controller.caretPosition(1) 1290e41f4b71Sopenharmony_ci }) 1291e41f4b71Sopenharmony_ci Button('Get CaretOffset') 1292e41f4b71Sopenharmony_ci .margin(15) 1293e41f4b71Sopenharmony_ci .onClick(() => { 1294e41f4b71Sopenharmony_ci this.positionInfo = this.controller.getCaretOffset() 1295e41f4b71Sopenharmony_ci }) 1296e41f4b71Sopenharmony_ci // Password text box. 1297e41f4b71Sopenharmony_ci TextInput({ placeholder: 'input your password...' }) 1298e41f4b71Sopenharmony_ci .width('95%') 1299e41f4b71Sopenharmony_ci .height(40) 1300e41f4b71Sopenharmony_ci .margin(20) 1301e41f4b71Sopenharmony_ci .type(InputType.Password) 1302e41f4b71Sopenharmony_ci .maxLength(9) 1303e41f4b71Sopenharmony_ci .showPasswordIcon(true) 1304e41f4b71Sopenharmony_ci .showPassword(this.passwordState) 1305e41f4b71Sopenharmony_ci .onSecurityStateChange(((isShowPassword: boolean) => { 1306e41f4b71Sopenharmony_ci // Update the password visibility. 1307e41f4b71Sopenharmony_ci console.info('isShowPassword',isShowPassword) 1308e41f4b71Sopenharmony_ci this.passwordState = isShowPassword 1309e41f4b71Sopenharmony_ci })) 1310e41f4b71Sopenharmony_ci // Email address autofill. 1311e41f4b71Sopenharmony_ci TextInput({ placeholder: 'input your email...' }) 1312e41f4b71Sopenharmony_ci .width('95%') 1313e41f4b71Sopenharmony_ci .height(40) 1314e41f4b71Sopenharmony_ci .margin(20) 1315e41f4b71Sopenharmony_ci .contentType(ContentType.EMAIL_ADDRESS) 1316e41f4b71Sopenharmony_ci .maxLength(9) 1317e41f4b71Sopenharmony_ci // Inline-style text box. 1318e41f4b71Sopenharmony_ci TextInput({ text: 'inline style' }) 1319e41f4b71Sopenharmony_ci .width('95%') 1320e41f4b71Sopenharmony_ci .height(50) 1321e41f4b71Sopenharmony_ci .margin(20) 1322e41f4b71Sopenharmony_ci .borderRadius(0) 1323e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1324e41f4b71Sopenharmony_ci }.width('100%') 1325e41f4b71Sopenharmony_ci } 1326e41f4b71Sopenharmony_ci} 1327e41f4b71Sopenharmony_ci``` 1328e41f4b71Sopenharmony_ci 1329e41f4b71Sopenharmony_ci 1330e41f4b71Sopenharmony_ci 1331e41f4b71Sopenharmony_ci### Example 2 1332e41f4b71Sopenharmony_ciThis example showcases the use of the **passwordIcon**, **showUnderline**, **showUnit**, and **showError** attributes. 1333e41f4b71Sopenharmony_ci```ts 1334e41f4b71Sopenharmony_ci@Entry 1335e41f4b71Sopenharmony_ci@Component 1336e41f4b71Sopenharmony_cistruct TextInputExample { 1337e41f4b71Sopenharmony_ci @State PassWordSrc1: Resource = $r('app.media.onIcon') 1338e41f4b71Sopenharmony_ci @State PassWordSrc2: Resource = $r('app.media.offIcon') 1339e41f4b71Sopenharmony_ci @State TextError: string = '' 1340e41f4b71Sopenharmony_ci @State Text: string = '' 1341e41f4b71Sopenharmony_ci @State NameText: string = 'test' 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ci @Builder itemEnd() { 1344e41f4b71Sopenharmony_ci Select([{ value: 'KB' }, 1345e41f4b71Sopenharmony_ci { value: 'MB' }, 1346e41f4b71Sopenharmony_ci { value: 'GB' }, 1347e41f4b71Sopenharmony_ci { value: 'TB', }]) 1348e41f4b71Sopenharmony_ci .height("48vp") 1349e41f4b71Sopenharmony_ci .borderRadius(0) 1350e41f4b71Sopenharmony_ci .selected(2) 1351e41f4b71Sopenharmony_ci .align(Alignment.Center) 1352e41f4b71Sopenharmony_ci .value('MB') 1353e41f4b71Sopenharmony_ci .font({ size: 20, weight: 500 }) 1354e41f4b71Sopenharmony_ci .fontColor('#182431') 1355e41f4b71Sopenharmony_ci .selectedOptionFont({ size: 20, weight: 400 }) 1356e41f4b71Sopenharmony_ci .optionFont({ size: 20, weight: 400 }) 1357e41f4b71Sopenharmony_ci .backgroundColor(Color.Transparent) 1358e41f4b71Sopenharmony_ci .responseRegion({ height: "40vp", width: "80%", x: '10%', y: '6vp' }) 1359e41f4b71Sopenharmony_ci .onSelect((index: number) => { 1360e41f4b71Sopenharmony_ci console.info('Select:' + index) 1361e41f4b71Sopenharmony_ci }) 1362e41f4b71Sopenharmony_ci } 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ci build() { 1365e41f4b71Sopenharmony_ci Column({ space: 20 }) { 1366e41f4b71Sopenharmony_ci // Customize the password icon. 1367e41f4b71Sopenharmony_ci TextInput({ placeholder: 'Custom password icon' }) 1368e41f4b71Sopenharmony_ci .type(InputType.Password) 1369e41f4b71Sopenharmony_ci .width(380) 1370e41f4b71Sopenharmony_ci .height(60) 1371e41f4b71Sopenharmony_ci .passwordIcon({ onIconSrc: this.PassWordSrc1, offIconSrc: this.PassWordSrc2 }) 1372e41f4b71Sopenharmony_ci // Show an underline. 1373e41f4b71Sopenharmony_ci TextInput({ placeholder: 'Underline style' }) 1374e41f4b71Sopenharmony_ci .showUnderline(true) 1375e41f4b71Sopenharmony_ci .width(380) 1376e41f4b71Sopenharmony_ci .height(60) 1377e41f4b71Sopenharmony_ci .showError('Error') 1378e41f4b71Sopenharmony_ci .showUnit(this.itemEnd) 1379e41f4b71Sopenharmony_ci 1380e41f4b71Sopenharmony_ci Text (`User name: ${this.Text}`) 1381e41f4b71Sopenharmony_ci .width('95%') 1382e41f4b71Sopenharmony_ci TextInput({ placeholder: 'Enter user name', text: this.Text }) 1383e41f4b71Sopenharmony_ci .showUnderline(true) 1384e41f4b71Sopenharmony_ci .width(380) 1385e41f4b71Sopenharmony_ci .showError(this.TextError) 1386e41f4b71Sopenharmony_ci .onChange((value: string) => { 1387e41f4b71Sopenharmony_ci this.Text = value 1388e41f4b71Sopenharmony_ci }) 1389e41f4b71Sopenharmony_ci .onSubmit(() => {// If the entered user name is incorrect, the text box will be cleared and the error message will be displayed. 1390e41f4b71Sopenharmony_ci if (this.Text == this.NameText) { 1391e41f4b71Sopenharmony_ci this.TextError = '' 1392e41f4b71Sopenharmony_ci } else { 1393e41f4b71Sopenharmony_ci this.TextError ='Incorrect user name.' 1394e41f4b71Sopenharmony_ci this.Text = '' 1395e41f4b71Sopenharmony_ci } 1396e41f4b71Sopenharmony_ci }) 1397e41f4b71Sopenharmony_ci 1398e41f4b71Sopenharmony_ci }.width('100%') 1399e41f4b71Sopenharmony_ci } 1400e41f4b71Sopenharmony_ci} 1401e41f4b71Sopenharmony_ci``` 1402e41f4b71Sopenharmony_ci 1403e41f4b71Sopenharmony_ci 1404e41f4b71Sopenharmony_ci 1405e41f4b71Sopenharmony_ci### Example 3 1406e41f4b71Sopenharmony_ciThis example illustrates how to bind a custom keyboard to the **TextInput** component. 1407e41f4b71Sopenharmony_ci```ts 1408e41f4b71Sopenharmony_ci// xxx.ets 1409e41f4b71Sopenharmony_ci@Entry 1410e41f4b71Sopenharmony_ci@Component 1411e41f4b71Sopenharmony_cistruct TextInputExample { 1412e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 1413e41f4b71Sopenharmony_ci @State inputValue: string = "" 1414e41f4b71Sopenharmony_ci 1415e41f4b71Sopenharmony_ci // Create a custom keyboard component. 1416e41f4b71Sopenharmony_ci @Builder CustomKeyboardBuilder() { 1417e41f4b71Sopenharmony_ci Column() { 1418e41f4b71Sopenharmony_ci Button('x').onClick(() => { 1419e41f4b71Sopenharmony_ci // Disable the custom keyboard. 1420e41f4b71Sopenharmony_ci this.controller.stopEditing() 1421e41f4b71Sopenharmony_ci }) 1422e41f4b71Sopenharmony_ci Grid() { 1423e41f4b71Sopenharmony_ci ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item:number|string) => { 1424e41f4b71Sopenharmony_ci GridItem() { 1425e41f4b71Sopenharmony_ci Button(item + "") 1426e41f4b71Sopenharmony_ci .width(110).onClick(() => { 1427e41f4b71Sopenharmony_ci this.inputValue += item 1428e41f4b71Sopenharmony_ci }) 1429e41f4b71Sopenharmony_ci } 1430e41f4b71Sopenharmony_ci }) 1431e41f4b71Sopenharmony_ci }.maxCount(3).columnsGap(10).rowsGap(10).padding(5) 1432e41f4b71Sopenharmony_ci }.backgroundColor(Color.Gray) 1433e41f4b71Sopenharmony_ci } 1434e41f4b71Sopenharmony_ci 1435e41f4b71Sopenharmony_ci build() { 1436e41f4b71Sopenharmony_ci Column() { 1437e41f4b71Sopenharmony_ci TextInput({ controller: this.controller, text: this.inputValue }) 1438e41f4b71Sopenharmony_ci // Bind the custom keyboard. 1439e41f4b71Sopenharmony_ci .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 }).height('48vp') 1440e41f4b71Sopenharmony_ci } 1441e41f4b71Sopenharmony_ci } 1442e41f4b71Sopenharmony_ci} 1443e41f4b71Sopenharmony_ci``` 1444e41f4b71Sopenharmony_ci 1445e41f4b71Sopenharmony_ci 1446e41f4b71Sopenharmony_ci 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci### Example 4 1449e41f4b71Sopenharmony_ciThis example demonstrates the use of the **cancelButton** API. 1450e41f4b71Sopenharmony_ci```ts 1451e41f4b71Sopenharmony_ci// xxx.ets 1452e41f4b71Sopenharmony_ci@Entry 1453e41f4b71Sopenharmony_ci@Component 1454e41f4b71Sopenharmony_cistruct ClearNodeExample { 1455e41f4b71Sopenharmony_ci @State text: string = '' 1456e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_ci build() { 1459e41f4b71Sopenharmony_ci Column() { 1460e41f4b71Sopenharmony_ci TextInput({ placeholder: 'input ...', controller: this.controller }) 1461e41f4b71Sopenharmony_ci .width(380) 1462e41f4b71Sopenharmony_ci .height(60) 1463e41f4b71Sopenharmony_ci .cancelButton({ 1464e41f4b71Sopenharmony_ci style: CancelButtonStyle.CONSTANT, 1465e41f4b71Sopenharmony_ci icon: { 1466e41f4b71Sopenharmony_ci size: 45, 1467e41f4b71Sopenharmony_ci src: $r('app.media.icon'), 1468e41f4b71Sopenharmony_ci color: Color.Blue 1469e41f4b71Sopenharmony_ci } 1470e41f4b71Sopenharmony_ci }) 1471e41f4b71Sopenharmony_ci .onChange((value: string) => { 1472e41f4b71Sopenharmony_ci this.text = value 1473e41f4b71Sopenharmony_ci }) 1474e41f4b71Sopenharmony_ci } 1475e41f4b71Sopenharmony_ci } 1476e41f4b71Sopenharmony_ci} 1477e41f4b71Sopenharmony_ci``` 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ci 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ci### Example 5 1482e41f4b71Sopenharmony_ciThis example illustrates the use of a character counter with the **TextInput** component. 1483e41f4b71Sopenharmony_ci```ts 1484e41f4b71Sopenharmony_ci// xxx.ets 1485e41f4b71Sopenharmony_ci@Entry 1486e41f4b71Sopenharmony_ci@Component 1487e41f4b71Sopenharmony_cistruct TextInputExample { 1488e41f4b71Sopenharmony_ci @State text: string = '' 1489e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 1490e41f4b71Sopenharmony_ci 1491e41f4b71Sopenharmony_ci build() { 1492e41f4b71Sopenharmony_ci Column() { 1493e41f4b71Sopenharmony_ci TextInput({ text: this.text, controller: this.controller }) 1494e41f4b71Sopenharmony_ci .placeholderFont({ size: 16, weight: 400 }) 1495e41f4b71Sopenharmony_ci .width(336) 1496e41f4b71Sopenharmony_ci .height(56) 1497e41f4b71Sopenharmony_ci .maxLength(6) 1498e41f4b71Sopenharmony_ci .showUnderline(true) 1499e41f4b71Sopenharmony_ci .showCounter(true, { thresholdPercentage: 50, highlightBorder: true }) 1500e41f4b71Sopenharmony_ci // The character counter is in this format: Number of characters that have been entered/Maximum number of characters allowed, which is specified by maxLength(). 1501e41f4b71Sopenharmony_ci // The character counter is displayed when the number of characters that have been entered is greater than the maximum number of characters multiplied by 50% (threshold percentage). 1502e41f4b71Sopenharmony_ci // When highlightBorder is set to false, the text box border turns red when the number of entered characters reaches the maximum. The default value is true. 1503e41f4b71Sopenharmony_ci .onChange((value: string) => { 1504e41f4b71Sopenharmony_ci this.text = value 1505e41f4b71Sopenharmony_ci }) 1506e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 1507e41f4b71Sopenharmony_ci } 1508e41f4b71Sopenharmony_ci} 1509e41f4b71Sopenharmony_ci``` 1510e41f4b71Sopenharmony_ci 1511e41f4b71Sopenharmony_ci 1512e41f4b71Sopenharmony_ci 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ci### Example 6 1515e41f4b71Sopenharmony_ciThis example presents how to format a telephone number as XXX XXXX XXXX using the **TextInput** component. 1516e41f4b71Sopenharmony_ci 1517e41f4b71Sopenharmony_ci```ts 1518e41f4b71Sopenharmony_ci@Entry 1519e41f4b71Sopenharmony_ci@Component 1520e41f4b71Sopenharmony_cistruct phone_example { 1521e41f4b71Sopenharmony_ci @State submitValue: string = '' 1522e41f4b71Sopenharmony_ci @State text: string = '' 1523e41f4b71Sopenharmony_ci public readonly NUM_TEXT_MAXSIZE_LENGTH = 13 1524e41f4b71Sopenharmony_ci @State teleNumberNoSpace: string = "" 1525e41f4b71Sopenharmony_ci @State nextCaret: number = -1 // Used to record the position for the next caret setting 1526e41f4b71Sopenharmony_ci @State actualCh: number = -1 // Used to record the insertion or deletion position relative to the i-th digit of the caret 1527e41f4b71Sopenharmony_ci @State lastCaretPosition: number = 0 1528e41f4b71Sopenharmony_ci @State lastCaretPositionEnd: number = 0 1529e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci isEmpty(str?: string): boolean { 1532e41f4b71Sopenharmony_ci return str == 'undefined' || !str || !new RegExp("[^\\s]").test(str) 1533e41f4b71Sopenharmony_ci } 1534e41f4b71Sopenharmony_ci 1535e41f4b71Sopenharmony_ci checkNeedNumberSpace(numText: string) { 1536e41f4b71Sopenharmony_ci let isSpace: RegExp = new RegExp('[\\+;,#\\*]', 'g') 1537e41f4b71Sopenharmony_ci let isRule: RegExp = new RegExp('^\\+.*') 1538e41f4b71Sopenharmony_ci 1539e41f4b71Sopenharmony_ci if (isSpace.test(numText)) { 1540e41f4b71Sopenharmony_ci // If the phone number contains special characters, no space is added. 1541e41f4b71Sopenharmony_ci if (isRule.test(numText)) { 1542e41f4b71Sopenharmony_ci return true 1543e41f4b71Sopenharmony_ci } else { 1544e41f4b71Sopenharmony_ci return false 1545e41f4b71Sopenharmony_ci } 1546e41f4b71Sopenharmony_ci } 1547e41f4b71Sopenharmony_ci return true; 1548e41f4b71Sopenharmony_ci } 1549e41f4b71Sopenharmony_ci 1550e41f4b71Sopenharmony_ci removeSpace(str: string): string { 1551e41f4b71Sopenharmony_ci if (this.isEmpty(str)) { 1552e41f4b71Sopenharmony_ci return '' 1553e41f4b71Sopenharmony_ci } 1554e41f4b71Sopenharmony_ci return str.replace(new RegExp("[\\s]", "g"), '') 1555e41f4b71Sopenharmony_ci } 1556e41f4b71Sopenharmony_ci 1557e41f4b71Sopenharmony_ci setCaret() { 1558e41f4b71Sopenharmony_ci if (this.nextCaret != -1) { 1559e41f4b71Sopenharmony_ci console.log("to keep caret position right, change caret to", this.nextCaret) 1560e41f4b71Sopenharmony_ci this.controller.caretPosition(this.nextCaret) 1561e41f4b71Sopenharmony_ci this.nextCaret = -1 1562e41f4b71Sopenharmony_ci } 1563e41f4b71Sopenharmony_ci } 1564e41f4b71Sopenharmony_ci 1565e41f4b71Sopenharmony_ci calcCaretPosition(nextText: string) { 1566e41f4b71Sopenharmony_ci let befNumberNoSpace: string = this.removeSpace(this.text) 1567e41f4b71Sopenharmony_ci this.actualCh = 0 1568e41f4b71Sopenharmony_ci if (befNumberNoSpace.length < this.teleNumberNoSpace.length) { // Insertion scenario 1569e41f4b71Sopenharmony_ci for (let i = 0; i < this.lastCaretPosition; i++) { 1570e41f4b71Sopenharmony_ci if (this.text[i] != ' ') { 1571e41f4b71Sopenharmony_ci this.actualCh += 1 1572e41f4b71Sopenharmony_ci } 1573e41f4b71Sopenharmony_ci } 1574e41f4b71Sopenharmony_ci this.actualCh += this.teleNumberNoSpace.length - befNumberNoSpace.length 1575e41f4b71Sopenharmony_ci console.log("actualCh: " + this.actualCh) 1576e41f4b71Sopenharmony_ci for (let i = 0; i < nextText.length; i++) { 1577e41f4b71Sopenharmony_ci if (nextText[i] != ' ') { 1578e41f4b71Sopenharmony_ci this.actualCh -= 1 1579e41f4b71Sopenharmony_ci if (this.actualCh <= 0) { 1580e41f4b71Sopenharmony_ci this.nextCaret = i + 1 1581e41f4b71Sopenharmony_ci break; 1582e41f4b71Sopenharmony_ci } 1583e41f4b71Sopenharmony_ci } 1584e41f4b71Sopenharmony_ci } 1585e41f4b71Sopenharmony_ci } else if (befNumberNoSpace.length > this.teleNumberNoSpace.length) { // Deletion scenario 1586e41f4b71Sopenharmony_ci if (this.lastCaretPosition === this.text.length) { 1587e41f4b71Sopenharmony_ci console.log("Caret at last, no need to change") 1588e41f4b71Sopenharmony_ci } else if (this.lastCaretPosition === this.lastCaretPositionEnd) { 1589e41f4b71Sopenharmony_ci // Scenario where the backspace key on the keyboard is used to delete characters one by one 1590e41f4b71Sopenharmony_ci for (let i = this.lastCaretPosition; i < this.text.length; i++) { 1591e41f4b71Sopenharmony_ci if (this.text[i] != ' ') { 1592e41f4b71Sopenharmony_ci this.actualCh += 1 1593e41f4b71Sopenharmony_ci } 1594e41f4b71Sopenharmony_ci } 1595e41f4b71Sopenharmony_ci for (let i = nextText.length - 1; i >= 0; i--) { 1596e41f4b71Sopenharmony_ci if (nextText[i] != ' ') { 1597e41f4b71Sopenharmony_ci this.actualCh -= 1 1598e41f4b71Sopenharmony_ci if (this.actualCh <= 0) { 1599e41f4b71Sopenharmony_ci this.nextCaret = i 1600e41f4b71Sopenharmony_ci break; 1601e41f4b71Sopenharmony_ci } 1602e41f4b71Sopenharmony_ci } 1603e41f4b71Sopenharmony_ci } 1604e41f4b71Sopenharmony_ci } else { 1605e41f4b71Sopenharmony_ci // When cutting or selecting text with a handle to delete multiple characters at once 1606e41f4b71Sopenharmony_ci this.nextCaret = this.lastCaretPosition // Maintain the caret position. 1607e41f4b71Sopenharmony_ci } 1608e41f4b71Sopenharmony_ci } 1609e41f4b71Sopenharmony_ci } 1610e41f4b71Sopenharmony_ci 1611e41f4b71Sopenharmony_ci build() { 1612e41f4b71Sopenharmony_ci Column() { 1613e41f4b71Sopenharmony_ci Row() { 1614e41f4b71Sopenharmony_ci TextInput({ text: `${this.text}`, controller: this.controller }).type(InputType.PhoneNumber).height('48vp') 1615e41f4b71Sopenharmony_ci .onChange((number: string) => { 1616e41f4b71Sopenharmony_ci this.teleNumberNoSpace = this.removeSpace(number); 1617e41f4b71Sopenharmony_ci let nextText: string = "" 1618e41f4b71Sopenharmony_ci if (this.teleNumberNoSpace.length > this.NUM_TEXT_MAXSIZE_LENGTH - 2) { 1619e41f4b71Sopenharmony_ci nextText = this.teleNumberNoSpace 1620e41f4b71Sopenharmony_ci } else if (this.checkNeedNumberSpace(number)) { 1621e41f4b71Sopenharmony_ci if (this.teleNumberNoSpace.length <= 3) { 1622e41f4b71Sopenharmony_ci nextText = this.teleNumberNoSpace 1623e41f4b71Sopenharmony_ci } else { 1624e41f4b71Sopenharmony_ci let split1: string = this.teleNumberNoSpace.substring(0, 3) 1625e41f4b71Sopenharmony_ci let split2: string = this.teleNumberNoSpace.substring(3) 1626e41f4b71Sopenharmony_ci nextText = split1 + ' ' + split2 1627e41f4b71Sopenharmony_ci if (this.teleNumberNoSpace.length > 7) { 1628e41f4b71Sopenharmony_ci split2 = this.teleNumberNoSpace.substring(3, 7) 1629e41f4b71Sopenharmony_ci let split3: string = this.teleNumberNoSpace.substring(7) 1630e41f4b71Sopenharmony_ci nextText = split1 + ' ' + split2 + ' ' + split3 1631e41f4b71Sopenharmony_ci } 1632e41f4b71Sopenharmony_ci } 1633e41f4b71Sopenharmony_ci } else { 1634e41f4b71Sopenharmony_ci nextText = number 1635e41f4b71Sopenharmony_ci } 1636e41f4b71Sopenharmony_ci console.log("onChange Triggered:" + this.text + "|" + nextText + "|" + number) 1637e41f4b71Sopenharmony_ci if (this.text === nextText && nextText === number) { 1638e41f4b71Sopenharmony_ci // The number has been formatted. Changing the caret position at this time will not reset the number. 1639e41f4b71Sopenharmony_ci this.setCaret() 1640e41f4b71Sopenharmony_ci } else { 1641e41f4b71Sopenharmony_ci this.calcCaretPosition(nextText) 1642e41f4b71Sopenharmony_ci } 1643e41f4b71Sopenharmony_ci this.text = nextText 1644e41f4b71Sopenharmony_ci }) 1645e41f4b71Sopenharmony_ci .onTextSelectionChange((selectionStart, selectionEnd) => { 1646e41f4b71Sopenharmony_ci // Record the caret position. 1647e41f4b71Sopenharmony_ci console.log("selection change: ", selectionStart, selectionEnd) 1648e41f4b71Sopenharmony_ci this.lastCaretPosition = selectionStart 1649e41f4b71Sopenharmony_ci this.lastCaretPositionEnd = selectionEnd 1650e41f4b71Sopenharmony_ci }) 1651e41f4b71Sopenharmony_ci } 1652e41f4b71Sopenharmony_ci } 1653e41f4b71Sopenharmony_ci .width('100%') 1654e41f4b71Sopenharmony_ci .height("100%") 1655e41f4b71Sopenharmony_ci } 1656e41f4b71Sopenharmony_ci} 1657e41f4b71Sopenharmony_ci``` 1658e41f4b71Sopenharmony_ci 1659e41f4b71Sopenharmony_ci 1660e41f4b71Sopenharmony_ci### Example 7 1661e41f4b71Sopenharmony_ci 1662e41f4b71Sopenharmony_ciThis example shows how to set the color of the underline when it is shown. 1663e41f4b71Sopenharmony_ci 1664e41f4b71Sopenharmony_ci```ts 1665e41f4b71Sopenharmony_ci@Entry 1666e41f4b71Sopenharmony_ci@Component 1667e41f4b71Sopenharmony_cistruct Index { 1668e41f4b71Sopenharmony_ci 1669e41f4b71Sopenharmony_ci build() { 1670e41f4b71Sopenharmony_ci Row() { 1671e41f4b71Sopenharmony_ci Column() { 1672e41f4b71Sopenharmony_ci TextInput({placeholder:'Placeholder text'}) 1673e41f4b71Sopenharmony_ci .showUnderline(true) 1674e41f4b71Sopenharmony_ci .underlineColor({normal:Color.Orange,typing:Color.Green,error:Color.Red,disable:Color.Gray}); 1675e41f4b71Sopenharmony_ci TextInput({placeholder:'Placeholder text'}) 1676e41f4b71Sopenharmony_ci .showUnderline(true) 1677e41f4b71Sopenharmony_ci .underlineColor(Color.Gray); 1678e41f4b71Sopenharmony_ci } 1679e41f4b71Sopenharmony_ci .width('100%') 1680e41f4b71Sopenharmony_ci } 1681e41f4b71Sopenharmony_ci .height('100%') 1682e41f4b71Sopenharmony_ci } 1683e41f4b71Sopenharmony_ci} 1684e41f4b71Sopenharmony_ci``` 1685e41f4b71Sopenharmony_ci 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci 1688e41f4b71Sopenharmony_ci 1689e41f4b71Sopenharmony_ci### Example 8 1690e41f4b71Sopenharmony_ciThis example shows how to set the **wordBreak** attribute for the **TextInput** component. 1691e41f4b71Sopenharmony_ci 1692e41f4b71Sopenharmony_ci```ts 1693e41f4b71Sopenharmony_ci// xxx.ets 1694e41f4b71Sopenharmony_ci@Entry 1695e41f4b71Sopenharmony_ci@Component 1696e41f4b71Sopenharmony_cistruct TextInputExample { 1697e41f4b71Sopenharmony_ci build() { 1698e41f4b71Sopenharmony_ci Column() { 1699e41f4b71Sopenharmony_ci Text("WordBreakType as NORMAL in the inline input style:").fontSize(16).fontColor(0xFF0000) 1700e41f4b71Sopenharmony_ci TextInput({ 1701e41f4b71Sopenharmony_ci text: 'This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.' 1702e41f4b71Sopenharmony_ci }) 1703e41f4b71Sopenharmony_ci .fontSize(16) 1704e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) // Inline input style 1705e41f4b71Sopenharmony_ci .wordBreak(WordBreak.NORMAL) // This attribute does not take effect for the non-inline input style. 1706e41f4b71Sopenharmony_ci 1707e41f4b71Sopenharmony_ci Text("WordBreakType as BREAK_ALL in the inline input style:").fontSize(16).fontColor(0xFF0000) 1708e41f4b71Sopenharmony_ci TextInput({ 1709e41f4b71Sopenharmony_ci text: 'This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.' 1710e41f4b71Sopenharmony_ci }) 1711e41f4b71Sopenharmony_ci .fontSize(16) 1712e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1713e41f4b71Sopenharmony_ci .wordBreak(WordBreak.BREAK_ALL) 1714e41f4b71Sopenharmony_ci 1715e41f4b71Sopenharmony_ci Text("WordBreakType as BREAK_ALL in the inline input style:").fontSize(16).fontColor(0xFF0000) 1716e41f4b71Sopenharmony_ci TextInput({ 1717e41f4b71Sopenharmony_ci text: 'In a multi-line text input component, when the text content entered exceeds the width of the component, it will automatically wrap to display.\nIf the height is not set, the component has no default height and will adapt to the height of the content. If the width is not set, it auto-fills the maximum width available.' 1718e41f4b71Sopenharmony_ci }) 1719e41f4b71Sopenharmony_ci .fontSize(16) 1720e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1721e41f4b71Sopenharmony_ci .wordBreak(WordBreak.BREAK_ALL) 1722e41f4b71Sopenharmony_ci 1723e41f4b71Sopenharmony_ci Text("WordBreakType as BREAK_WORD in the inline input style:").fontSize(16).fontColor(0xFF0000) 1724e41f4b71Sopenharmony_ci TextInput({ 1725e41f4b71Sopenharmony_ci text: 'This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.' 1726e41f4b71Sopenharmony_ci }) 1727e41f4b71Sopenharmony_ci .fontSize(16) 1728e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1729e41f4b71Sopenharmony_ci .wordBreak(WordBreak.BREAK_WORD) 1730e41f4b71Sopenharmony_ci } 1731e41f4b71Sopenharmony_ci } 1732e41f4b71Sopenharmony_ci} 1733e41f4b71Sopenharmony_ci``` 1734e41f4b71Sopenharmony_ci 1735e41f4b71Sopenharmony_ci 1736e41f4b71Sopenharmony_ci### Example 9 1737e41f4b71Sopenharmony_ci 1738e41f4b71Sopenharmony_ciThis example shows how to use the **lineHeight**, **letterSpacing**, and **decoration** attributes. 1739e41f4b71Sopenharmony_ci 1740e41f4b71Sopenharmony_ci```ts 1741e41f4b71Sopenharmony_ci@Entry 1742e41f4b71Sopenharmony_ci@Component 1743e41f4b71Sopenharmony_cistruct TextInputExample { 1744e41f4b71Sopenharmony_ci build() { 1745e41f4b71Sopenharmony_ci Row() { 1746e41f4b71Sopenharmony_ci Column() { 1747e41f4b71Sopenharmony_ci Text('lineHeight').fontSize(9).fontColor(0xCCCCCC) 1748e41f4b71Sopenharmony_ci TextInput({text: 'lineHeight unset'}) 1749e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(10).margin(5) 1750e41f4b71Sopenharmony_ci TextInput({text: 'lineHeight 15'}) 1751e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(10).margin(5).lineHeight(15) 1752e41f4b71Sopenharmony_ci TextInput({text: 'lineHeight 30'}) 1753e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(10).margin(5).lineHeight(30) 1754e41f4b71Sopenharmony_ci 1755e41f4b71Sopenharmony_ci Text('letterSpacing').fontSize(9).fontColor(0xCCCCCC) 1756e41f4b71Sopenharmony_ci TextInput({text: 'letterSpacing 0'}) 1757e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5).letterSpacing(0) 1758e41f4b71Sopenharmony_ci TextInput({text: 'letterSpacing 3'}) 1759e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5).letterSpacing(3) 1760e41f4b71Sopenharmony_ci TextInput({text: 'letterSpacing -1'}) 1761e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5).letterSpacing(-1) 1762e41f4b71Sopenharmony_ci 1763e41f4b71Sopenharmony_ci Text('decoration').fontSize(9).fontColor(0xCCCCCC) 1764e41f4b71Sopenharmony_ci TextInput({text: 'LineThrough, Red'}) 1765e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5) 1766e41f4b71Sopenharmony_ci .decoration({type: TextDecorationType.LineThrough, color: Color.Red}) 1767e41f4b71Sopenharmony_ci TextInput({text: 'Overline, Red, DASHED'}) 1768e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5) 1769e41f4b71Sopenharmony_ci .decoration({type: TextDecorationType.Overline, color: Color.Red, style: TextDecorationStyle.DASHED}) 1770e41f4b71Sopenharmony_ci TextInput({text: 'Underline, Red, WAVY'}) 1771e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5) 1772e41f4b71Sopenharmony_ci .decoration({type: TextDecorationType.Underline, color: Color.Red, style: TextDecorationStyle.WAVY}) 1773e41f4b71Sopenharmony_ci }.height('90%') 1774e41f4b71Sopenharmony_ci } 1775e41f4b71Sopenharmony_ci .width('90%') 1776e41f4b71Sopenharmony_ci .margin(10) 1777e41f4b71Sopenharmony_ci } 1778e41f4b71Sopenharmony_ci} 1779e41f4b71Sopenharmony_ci``` 1780e41f4b71Sopenharmony_ci 1781e41f4b71Sopenharmony_ci 1782e41f4b71Sopenharmony_ci 1783e41f4b71Sopenharmony_ci### Example 10 1784e41f4b71Sopenharmony_ci 1785e41f4b71Sopenharmony_ciThis example shows how to set the **fontFeature** attribute, with a comparison between the ss01-enabled and ss01-disabled effects. 1786e41f4b71Sopenharmony_ci 1787e41f4b71Sopenharmony_ci```ts 1788e41f4b71Sopenharmony_ci@Entry 1789e41f4b71Sopenharmony_ci@Component 1790e41f4b71Sopenharmony_cistruct textInput { 1791e41f4b71Sopenharmony_ci @State text1: string = 'This is ss01 on : 0123456789' 1792e41f4b71Sopenharmony_ci @State text2: string = 'This is ss01 off: 0123456789' 1793e41f4b71Sopenharmony_ci 1794e41f4b71Sopenharmony_ci 1795e41f4b71Sopenharmony_ci build() { 1796e41f4b71Sopenharmony_ci Column(){ 1797e41f4b71Sopenharmony_ci TextInput({text: this.text1}) 1798e41f4b71Sopenharmony_ci .fontSize(20) 1799e41f4b71Sopenharmony_ci .margin({top:200}) 1800e41f4b71Sopenharmony_ci .fontFeature("\"ss01\" on") 1801e41f4b71Sopenharmony_ci TextInput({text : this.text2}) 1802e41f4b71Sopenharmony_ci .margin({top:10}) 1803e41f4b71Sopenharmony_ci .fontSize(20) 1804e41f4b71Sopenharmony_ci .fontFeature("\"ss01\" off") 1805e41f4b71Sopenharmony_ci } 1806e41f4b71Sopenharmony_ci .width("90%") 1807e41f4b71Sopenharmony_ci .margin("5%") 1808e41f4b71Sopenharmony_ci } 1809e41f4b71Sopenharmony_ci} 1810e41f4b71Sopenharmony_ci``` 1811e41f4b71Sopenharmony_ci 1812e41f4b71Sopenharmony_ci 1813e41f4b71Sopenharmony_ci 1814e41f4b71Sopenharmony_ci### Example 11 1815e41f4b71Sopenharmony_ci 1816e41f4b71Sopenharmony_ciThis example shows how to support custom keyboard avoidance. 1817e41f4b71Sopenharmony_ci 1818e41f4b71Sopenharmony_ci```ts 1819e41f4b71Sopenharmony_ci@Entry 1820e41f4b71Sopenharmony_ci@Component 1821e41f4b71Sopenharmony_cistruct Input { 1822e41f4b71Sopenharmony_ci controller: TextInputController = new TextInputController() 1823e41f4b71Sopenharmony_ci @State inputValue: string = "" 1824e41f4b71Sopenharmony_ci @State height1:string|number = '80%' 1825e41f4b71Sopenharmony_ci @State supportAvoidance:boolean = true; 1826e41f4b71Sopenharmony_ci // Create a custom keyboard component. 1827e41f4b71Sopenharmony_ci @Builder CustomKeyboardBuilder() { 1828e41f4b71Sopenharmony_ci Column() { 1829e41f4b71Sopenharmony_ci Row(){ 1830e41f4b71Sopenharmony_ci Button('x').onClick(() => { 1831e41f4b71Sopenharmony_ci // Disable the custom keyboard. 1832e41f4b71Sopenharmony_ci this.controller.stopEditing() 1833e41f4b71Sopenharmony_ci }).margin(10) 1834e41f4b71Sopenharmony_ci } 1835e41f4b71Sopenharmony_ci Grid() { 1836e41f4b71Sopenharmony_ci ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item:number|string) => { 1837e41f4b71Sopenharmony_ci GridItem() { 1838e41f4b71Sopenharmony_ci Button(item + "") 1839e41f4b71Sopenharmony_ci .width(110).onClick(() => { 1840e41f4b71Sopenharmony_ci this.inputValue += item 1841e41f4b71Sopenharmony_ci }) 1842e41f4b71Sopenharmony_ci } 1843e41f4b71Sopenharmony_ci }) 1844e41f4b71Sopenharmony_ci }.maxCount(3).columnsGap(10).rowsGap(10).padding(5) 1845e41f4b71Sopenharmony_ci }.backgroundColor(Color.Gray) 1846e41f4b71Sopenharmony_ci } 1847e41f4b71Sopenharmony_ci build() { 1848e41f4b71Sopenharmony_ci Column() { 1849e41f4b71Sopenharmony_ci Row(){ 1850e41f4b71Sopenharmony_ci Button("20%") 1851e41f4b71Sopenharmony_ci .fontSize(24) 1852e41f4b71Sopenharmony_ci .onClick(()=>{ 1853e41f4b71Sopenharmony_ci this.height1 = "20%" 1854e41f4b71Sopenharmony_ci }) 1855e41f4b71Sopenharmony_ci Button("80%") 1856e41f4b71Sopenharmony_ci .fontSize(24) 1857e41f4b71Sopenharmony_ci .margin({left:20}) 1858e41f4b71Sopenharmony_ci .onClick(()=>{ 1859e41f4b71Sopenharmony_ci this.height1 = "80%" 1860e41f4b71Sopenharmony_ci }) 1861e41f4b71Sopenharmony_ci } 1862e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 1863e41f4b71Sopenharmony_ci .alignItems(VerticalAlign.Bottom) 1864e41f4b71Sopenharmony_ci .height(this.height1) 1865e41f4b71Sopenharmony_ci .width("100%") 1866e41f4b71Sopenharmony_ci .padding({bottom:50}) 1867e41f4b71Sopenharmony_ci TextInput({ controller: this.controller, text: this.inputValue }) 1868e41f4b71Sopenharmony_ci // Bind the custom keyboard. 1869e41f4b71Sopenharmony_ci .customKeyboard(this.CustomKeyboardBuilder(),{ supportAvoidance: this.supportAvoidance }).margin(10).border({ width: 1 }) 1870e41f4b71Sopenharmony_ci 1871e41f4b71Sopenharmony_ci } 1872e41f4b71Sopenharmony_ci } 1873e41f4b71Sopenharmony_ci} 1874e41f4b71Sopenharmony_ci``` 1875e41f4b71Sopenharmony_ci 1876e41f4b71Sopenharmony_ci 1877e41f4b71Sopenharmony_ci 1878e41f4b71Sopenharmony_ci### Example 12 1879e41f4b71Sopenharmony_ci 1880e41f4b71Sopenharmony_ciThis example shows how to set **minFontSize**, **maxFontSize**, and **heightAdaptivePolicy**. 1881e41f4b71Sopenharmony_ci 1882e41f4b71Sopenharmony_ci```ts 1883e41f4b71Sopenharmony_ci@Entry 1884e41f4b71Sopenharmony_ci@Component 1885e41f4b71Sopenharmony_cistruct TextInputExample { 1886e41f4b71Sopenharmony_ci build() { 1887e41f4b71Sopenharmony_ci Row() { 1888e41f4b71Sopenharmony_ci Column() { 1889e41f4b71Sopenharmony_ci Text('heightAdaptivePolicy').fontSize(9).fontColor(0xCCCCCC) 1890e41f4b71Sopenharmony_ci TextInput({text: 'This is the text without the height adaptive policy set'}) 1891e41f4b71Sopenharmony_ci .width('80%').height(50).borderWidth(1).margin(1) 1892e41f4b71Sopenharmony_ci TextInput({text: 'This is the text with the height adaptive policy set'}) 1893e41f4b71Sopenharmony_ci .width('80%').height(50).borderWidth(1).margin(1) 1894e41f4b71Sopenharmony_ci .minFontSize(4) 1895e41f4b71Sopenharmony_ci .maxFontSize(40) 1896e41f4b71Sopenharmony_ci .maxLines(3) 1897e41f4b71Sopenharmony_ci .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1898e41f4b71Sopenharmony_ci TextInput({text: 'This is the text with the height adaptive policy set'}) 1899e41f4b71Sopenharmony_ci .width('80%').height(50).borderWidth(1).margin(1) 1900e41f4b71Sopenharmony_ci .minFontSize(4) 1901e41f4b71Sopenharmony_ci .maxFontSize(40) 1902e41f4b71Sopenharmony_ci .maxLines(3) 1903e41f4b71Sopenharmony_ci .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1904e41f4b71Sopenharmony_ci TextInput({text: 'This is the text with the height adaptive policy set'}) 1905e41f4b71Sopenharmony_ci .width('80%').height(50).borderWidth(1).margin(1) 1906e41f4b71Sopenharmony_ci .minFontSize(4) 1907e41f4b71Sopenharmony_ci .maxFontSize(40) 1908e41f4b71Sopenharmony_ci .maxLines(3) 1909e41f4b71Sopenharmony_ci .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1910e41f4b71Sopenharmony_ci }.height('90%') 1911e41f4b71Sopenharmony_ci } 1912e41f4b71Sopenharmony_ci .width('90%') 1913e41f4b71Sopenharmony_ci .margin(10) 1914e41f4b71Sopenharmony_ci } 1915e41f4b71Sopenharmony_ci} 1916e41f4b71Sopenharmony_ci``` 1917e41f4b71Sopenharmony_ci 1918e41f4b71Sopenharmony_ci 1919e41f4b71Sopenharmony_ci 1920e41f4b71Sopenharmony_ci### Example 13 1921e41f4b71Sopenharmony_ciThis example shows how to set the **lineBreakStrategy** attribute, with a comparison of line break rules. 1922e41f4b71Sopenharmony_ci 1923e41f4b71Sopenharmony_ci```ts 1924e41f4b71Sopenharmony_ci@Entry 1925e41f4b71Sopenharmony_ci@Component 1926e41f4b71Sopenharmony_cistruct TextExample1 { 1927e41f4b71Sopenharmony_ci @State message1: string = "They can be classified as built-in components–those directly provided by the ArkUI framework and custom components – those defined by developers" + 1928e41f4b71Sopenharmony_ci "The built-in components include buttons radio buttonsprogress indicators and text You can set the rendering effectof thesecomponents in method chaining mode," + 1929e41f4b71Sopenharmony_ci "page components are divided into independent UI units to implementindependent creation development and reuse of different units on pages making pages more engineering-oriented."; 1930e41f4b71Sopenharmony_ci 1931e41f4b71Sopenharmony_ci build() { 1932e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { 1933e41f4b71Sopenharmony_ci Text('LineBreakStrategy.GREEDY').fontSize(9).fontColor(0xCCCCCC).width('90%').padding(10) 1934e41f4b71Sopenharmony_ci TextInput({text: this.message1}) 1935e41f4b71Sopenharmony_ci .fontSize(12) 1936e41f4b71Sopenharmony_ci .border({ width: 1 }) 1937e41f4b71Sopenharmony_ci .padding(10) 1938e41f4b71Sopenharmony_ci .width('100%') 1939e41f4b71Sopenharmony_ci .maxLines(5) 1940e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1941e41f4b71Sopenharmony_ci .lineBreakStrategy(LineBreakStrategy.GREEDY) 1942e41f4b71Sopenharmony_ci Text('LineBreakStrategy.HIGH_QUALITY').fontSize(9).fontColor(0xCCCCCC).width('90%').padding(10) 1943e41f4b71Sopenharmony_ci TextInput({text: this.message1}) 1944e41f4b71Sopenharmony_ci .fontSize(12) 1945e41f4b71Sopenharmony_ci .border({ width: 1 }) 1946e41f4b71Sopenharmony_ci .padding(10) 1947e41f4b71Sopenharmony_ci .width('100%') 1948e41f4b71Sopenharmony_ci .maxLines(5) 1949e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1950e41f4b71Sopenharmony_ci .lineBreakStrategy(LineBreakStrategy.HIGH_QUALITY) 1951e41f4b71Sopenharmony_ci Text('LineBreakStrategy.BALANCED').fontSize(9).fontColor(0xCCCCCC).width('90%').padding(10) 1952e41f4b71Sopenharmony_ci TextInput({text: this.message1}) 1953e41f4b71Sopenharmony_ci .fontSize(12) 1954e41f4b71Sopenharmony_ci .border({ width: 1 }) 1955e41f4b71Sopenharmony_ci .padding(10) 1956e41f4b71Sopenharmony_ci .width('100%') 1957e41f4b71Sopenharmony_ci .maxLines(5) 1958e41f4b71Sopenharmony_ci .style(TextInputStyle.Inline) 1959e41f4b71Sopenharmony_ci .lineBreakStrategy(LineBreakStrategy.BALANCED) 1960e41f4b71Sopenharmony_ci }.height(700).width(370).padding({ left: 35, right: 35, top: 35 }) 1961e41f4b71Sopenharmony_ci } 1962e41f4b71Sopenharmony_ci} 1963e41f4b71Sopenharmony_ci``` 1964e41f4b71Sopenharmony_ci 1965e41f4b71Sopenharmony_ci 1966e41f4b71Sopenharmony_ci 1967e41f4b71Sopenharmony_ci### Example 14 1968e41f4b71Sopenharmony_ci 1969e41f4b71Sopenharmony_ciThis example shows how to use the insert and delete callbacks. 1970e41f4b71Sopenharmony_ci 1971e41f4b71Sopenharmony_ci```ts 1972e41f4b71Sopenharmony_ci// xxx.ets 1973e41f4b71Sopenharmony_ci@Entry 1974e41f4b71Sopenharmony_ci@Component 1975e41f4b71Sopenharmony_cistruct TextInputExample { 1976e41f4b71Sopenharmony_ci @State insertValue: string = "" 1977e41f4b71Sopenharmony_ci @State deleteValue: string = "" 1978e41f4b71Sopenharmony_ci @State insertOffset: number = 0 1979e41f4b71Sopenharmony_ci @State deleteOffset: number = 0 1980e41f4b71Sopenharmony_ci @State deleteDirection: number = 0 1981e41f4b71Sopenharmony_ci 1982e41f4b71Sopenharmony_ci build() { 1983e41f4b71Sopenharmony_ci Row() { 1984e41f4b71Sopenharmony_ci Column() { 1985e41f4b71Sopenharmony_ci TextInput({ text: "Insert callbacks" }) 1986e41f4b71Sopenharmony_ci .height(60) 1987e41f4b71Sopenharmony_ci .onWillInsert((info: InsertValue) => { 1988e41f4b71Sopenharmony_ci this.insertValue = info.insertValue 1989e41f4b71Sopenharmony_ci return true; 1990e41f4b71Sopenharmony_ci }) 1991e41f4b71Sopenharmony_ci .onDidInsert((info: InsertValue) => { 1992e41f4b71Sopenharmony_ci this.insertOffset = info.insertOffset 1993e41f4b71Sopenharmony_ci }) 1994e41f4b71Sopenharmony_ci 1995e41f4b71Sopenharmony_ci Text("insertValue:" + this.insertValue + " insertOffset:" + this.insertOffset).height(30) 1996e41f4b71Sopenharmony_ci 1997e41f4b71Sopenharmony_ci TextInput({ text: "Delete callbacks" }) 1998e41f4b71Sopenharmony_ci .height(60) 1999e41f4b71Sopenharmony_ci .onWillDelete((info: DeleteValue) => { 2000e41f4b71Sopenharmony_ci this.deleteValue = info.deleteValue 2001e41f4b71Sopenharmony_ci info.direction 2002e41f4b71Sopenharmony_ci return true; 2003e41f4b71Sopenharmony_ci }) 2004e41f4b71Sopenharmony_ci .onDidDelete((info: DeleteValue) => { 2005e41f4b71Sopenharmony_ci this.deleteOffset = info.deleteOffset 2006e41f4b71Sopenharmony_ci this.deleteDirection = info.direction 2007e41f4b71Sopenharmony_ci }) 2008e41f4b71Sopenharmony_ci 2009e41f4b71Sopenharmony_ci Text("deleteValue:" + this.deleteValue + " deleteOffset:" + this.deleteOffset).height(30) 2010e41f4b71Sopenharmony_ci Text("deleteDirection:" + (this.deleteDirection == 0 ? "BACKWARD" : "FORWARD")).height(30) 2011e41f4b71Sopenharmony_ci 2012e41f4b71Sopenharmony_ci }.width('100%') 2013e41f4b71Sopenharmony_ci } 2014e41f4b71Sopenharmony_ci .height('100%') 2015e41f4b71Sopenharmony_ci } 2016e41f4b71Sopenharmony_ci} 2017e41f4b71Sopenharmony_ci``` 2018e41f4b71Sopenharmony_ci 2019e41f4b71Sopenharmony_ci 2020e41f4b71Sopenharmony_ci 2021e41f4b71Sopenharmony_ci### Example 15 2022e41f4b71Sopenharmony_ci 2023e41f4b71Sopenharmony_ciThis example shows how to set **editMenuOptions**. 2024e41f4b71Sopenharmony_ci 2025e41f4b71Sopenharmony_ci```ts 2026e41f4b71Sopenharmony_ci// xxx.ets 2027e41f4b71Sopenharmony_ci@Entry 2028e41f4b71Sopenharmony_ci@Component 2029e41f4b71Sopenharmony_cistruct TextInputExample { 2030e41f4b71Sopenharmony_ci @State text: string = 'TextInput editMenuOptions' 2031e41f4b71Sopenharmony_ci 2032e41f4b71Sopenharmony_ci onCreateMenu(menuItems: Array<TextMenuItem>) { 2033e41f4b71Sopenharmony_ci menuItems.forEach((value, index) => { 2034e41f4b71Sopenharmony_ci value.icon = $r('app.media.startIcon') 2035e41f4b71Sopenharmony_ci if (value.id.equals(TextMenuItemId.COPY)) { 2036e41f4b71Sopenharmony_ci value.content = "Copy_custom" 2037e41f4b71Sopenharmony_ci } 2038e41f4b71Sopenharmony_ci if (value.id.equals(TextMenuItemId.SELECT_ALL)) { 2039e41f4b71Sopenharmony_ci value.content = "Select all_custom" 2040e41f4b71Sopenharmony_ci } 2041e41f4b71Sopenharmony_ci }) 2042e41f4b71Sopenharmony_ci let item1: TextMenuItem = { 2043e41f4b71Sopenharmony_ci content: 'Custom 1', 2044e41f4b71Sopenharmony_ci icon: $r('app.media.startIcon'), 2045e41f4b71Sopenharmony_ci id: TextMenuItemId.of('Custom 1'), 2046e41f4b71Sopenharmony_ci } 2047e41f4b71Sopenharmony_ci let item2: TextMenuItem = { 2048e41f4b71Sopenharmony_ci content: 'Custom 2', 2049e41f4b71Sopenharmony_ci id: TextMenuItemId.of('Custom 2'), 2050e41f4b71Sopenharmony_ci icon: $r('app.media.startIcon'), 2051e41f4b71Sopenharmony_ci } 2052e41f4b71Sopenharmony_ci menuItems.push(item1) 2053e41f4b71Sopenharmony_ci menuItems.unshift(item2) 2054e41f4b71Sopenharmony_ci return menuItems 2055e41f4b71Sopenharmony_ci } 2056e41f4b71Sopenharmony_ci 2057e41f4b71Sopenharmony_ci build() { 2058e41f4b71Sopenharmony_ci Column() { 2059e41f4b71Sopenharmony_ci TextInput({ text: this.text }) 2060e41f4b71Sopenharmony_ci .width('95%') 2061e41f4b71Sopenharmony_ci .height(50) 2062e41f4b71Sopenharmony_ci .editMenuOptions({ 2063e41f4b71Sopenharmony_ci onCreateMenu: this.onCreateMenu, onMenuItemClick: (menuItem: TextMenuItem, textRange: TextRange) => { 2064e41f4b71Sopenharmony_ci if (menuItem.id.equals(TextMenuItemId.of("custom2"))) { 2065e41f4b71Sopenharmony_ci console.log("Intercept id: custom2 start:" + textRange.start + "; end:" + textRange.end) 2066e41f4b71Sopenharmony_ci return true; 2067e41f4b71Sopenharmony_ci } 2068e41f4b71Sopenharmony_ci if (menuItem.id.equals(TextMenuItemId.COPY)) { 2069e41f4b71Sopenharmony_ci console.log("Intercept COPY start:" + textRange.start + "; end:" + textRange.end) 2070e41f4b71Sopenharmony_ci return true; 2071e41f4b71Sopenharmony_ci } 2072e41f4b71Sopenharmony_ci if (menuItem.id.equals(TextMenuItemId.SELECT_ALL)) { 2073e41f4b71Sopenharmony_ci console.log("Do not intercept SELECT_ALL start:" + textRange.start + "; end:" + textRange.end) 2074e41f4b71Sopenharmony_ci return false; 2075e41f4b71Sopenharmony_ci } 2076e41f4b71Sopenharmony_ci return false; 2077e41f4b71Sopenharmony_ci } 2078e41f4b71Sopenharmony_ci }) 2079e41f4b71Sopenharmony_ci .margin({ top: 100 }) 2080e41f4b71Sopenharmony_ci } 2081e41f4b71Sopenharmony_ci .width("90%") 2082e41f4b71Sopenharmony_ci .margin("5%") 2083e41f4b71Sopenharmony_ci } 2084e41f4b71Sopenharmony_ci} 2085e41f4b71Sopenharmony_ci``` 2086e41f4b71Sopenharmony_ci 2087e41f4b71Sopenharmony_ci 2088