1e41f4b71Sopenharmony_ci# TextArea 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **TextArea** component provides multi-line text input and automatically wraps text so that each line does not have more than the width of the component. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciIf the component does not have its height set, it adapts its height to the content. If the component does not have its width set, it takes the maximum available width. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Child Components 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciNot supported 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## APIs 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciTextArea(value?: TextAreaOptions) 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Parameters** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 28e41f4b71Sopenharmony_ci| ----- | ----- | ---- | ---- | 29e41f4b71Sopenharmony_ci| value | [TextAreaOptions](#textareaoptions) | No | Parameters of the **TextArea** component.| 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci## TextAreaOptions 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci| Name| Type | Mandatory | Description| 38e41f4b71Sopenharmony_ci| ---- | ----- | ---- | ---- | 39e41f4b71Sopenharmony_ci| placeholder | [ResourceStr](ts-types.md#resourcestr) | No | Text displayed when there is no input. <br>When only the **placeholder** attribute is set, the text selection handle is still available; the caret stays at the beginning of the placeholder text when the handle is released. | 40e41f4b71Sopenharmony_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).| 41e41f4b71Sopenharmony_ci| controller<sup>8+</sup> | [TextAreaController](#textareacontroller8) | No | Text area controller.| 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci## Attributes 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci> **NOTE** 49e41f4b71Sopenharmony_ci> 50e41f4b71Sopenharmony_ci> 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> } 51e41f4b71Sopenharmony_ci> 52e41f4b71Sopenharmony_ci> Since API version 11, **.width('auto')** can be set for the **TextArea** 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). 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci### placeholderColor 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciplaceholderColor(value: ResourceColor) 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ciSets the placeholder text color. 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**Parameters** 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 67e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------------- | 68e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Placeholder text color.<br>The default value follows the theme.| 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci### placeholderFont 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciplaceholderFont(value: Font) 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciSets the placeholder text style, including the font size, font width, font family, and font style. Currently, only the default font family is supported. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**Parameters** 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 83e41f4b71Sopenharmony_ci| ------ | ------------------------ | ---- | --------------------- | 84e41f4b71Sopenharmony_ci| value | [Font](ts-types.md#font) | Yes | Placeholder text style.| 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci### textAlign 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_citextAlign(value: TextAlign) 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciSets the horizontal alignment of the text. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ciAvailable options are **TextAlign.Start**, **TextAlign.Center**, and **TextAlign.End**. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_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. 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ciWhen **textAlign** is set to **TextAlign.JUSTIFY**, the text in the last line is horizontally aligned with the start edge. 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciSince API version 11, **textAlign** can be set to **TextAlign.JUSTIFY**. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**Parameters** 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 107e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ---------------------------------------------------------- | 108e41f4b71Sopenharmony_ci| value | [TextAlign](ts-appendix-enums.md#textalign) | Yes | Horizontal alignment of the text.<br>Default value: **TextAlign.Start**| 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci### caretColor 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_cicaretColor(value: ResourceColor) 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciSets the color of the caret in the text box. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**Parameters** 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 123e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------- | 124e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Color of the caret in the text box.<br>Default value: **'#007DFF'**| 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci> **NOTE** 127e41f4b71Sopenharmony_ci> Since API version 12, this API can be used to set the text handle color, which is the same as the caret color. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci### fontColor 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_cifontColor(value: ResourceColor) 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ciSets the font color. 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**Parameters** 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 144e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------- | 145e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Font color.| 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci### fontSize 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_cifontSize(value: number | string | Resource) 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ciSets the text size. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**Parameters** 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 162e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 163e41f4b71Sopenharmony_ci| value | [Resource](ts-types.md#resource) \| number \| string | Yes | Font size. If **fontSize** is of the number type, the unit fp is used. The default font size is 16 fp. This parameter cannot be set in percentage.| 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci### fontStyle 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_cifontStyle(value: FontStyle) 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ciSets the font style. 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci**Parameters** 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 180e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | --------------------------------------- | 181e41f4b71Sopenharmony_ci| value | [FontStyle](ts-appendix-enums.md#fontstyle) | Yes | Font style.<br>Default value: **FontStyle.Normal**| 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci### fontWeight 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_cifontWeight(value: number | FontWeight | string) 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ciSets the font weight. If the value is too large, the text may be clipped depending on the font. 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**Parameters** 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 198e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 199e41f4b71Sopenharmony_ci| value | [FontWeight](ts-appendix-enums.md#fontweight) \| number \| string | Yes | Font weight. For the number type, the value range is [100, 900], at an interval of 100. The default value is **400**. A larger value indicates a heavier font weight. For the string type, only strings that represent a number, for example, **"400"**, and the following enumerated values of **FontWeight** are supported: **"bold"**, **"bolder"**, **"lighter"**, **"regular"**, and **"medium"**.<br>Default value: **FontWeight.Normal**| 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci### fontFamily 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_cifontFamily(value: string | Resource) 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ciSets the font family. 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**Parameters** 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 216e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 217e41f4b71Sopenharmony_ci| value | [Resource](ts-types.md#resource) \| string | Yes | Font family. Default font: **'HarmonyOS Sans'**<br>The 'HarmonyOS Sans' font and [registered custom fonts](../js-apis-font.md) are supported for applications.<br>Only the 'HarmonyOS Sans' font is supported for widgets.| 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci### inputFilter<sup>8+</sup> 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ciinputFilter(value: ResourceStr, error?: (value: string) => void) 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_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. 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci**Parameters** 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 232e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | ---------------------------------- | 233e41f4b71Sopenharmony_ci| value | [ResourceStr](ts-types.md#resourcestr) | Yes | Regular expression. | 234e41f4b71Sopenharmony_ci| error | (value: string) => void | No | Filtered-out content to return when regular expression matching fails.| 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci### copyOption<sup>9+</sup> 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_cicopyOption(value: CopyOptions) 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ciSets whether copy and paste is allowed. If this attribute is set to **CopyOptions.None**, the paste operation is allowed, but the copy and cut operations are not. 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ciDragging is not allowed when **CopyOptions.None** is set. 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**Parameters** 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 251e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 252e41f4b71Sopenharmony_ci| value | [CopyOptions](ts-appendix-enums.md#copyoptions9) | Yes | Whether copy and paste is allowed.<br>Default value: **CopyOptions.LocalDevice**| 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci### maxLength<sup>10+</sup> 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_cimaxLength(value: number) 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ciSets the maximum number of characters for text input. By default, there is no maximum number of characters. When the maximum number of characters is reached, no more characters can be entered, and the border turns red. 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci**Parameters** 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 267e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------- | 268e41f4b71Sopenharmony_ci| value | number | Yes | Maximum number of characters for text input.| 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci### showCounter<sup>10+</sup> 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_cishowCounter(value: boolean, options?: InputCounterOptions) 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ciSets the character counter displayed when the number of characters entered exceeds the threshold. 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_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. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_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 reaches 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**. The character counter is not displayed for text boxes in inline input style. 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci**Parameters** 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 287e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ | ---- | ---------------- | 288e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to display the character counter.| 289e41f4b71Sopenharmony_ci| options<sup>11+</sup> | [InputCounterOptions](ts-types.md#inputcounteroptions11) | No | Threshold percentage of the character counter.| 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci### style<sup>10+</sup> 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_cistyle(value: TextContentStyle) 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ciSets the polymorphic style of the text box. The inline input style is only available for the **TextAreaType.Normal** type. 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**Parameters** 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 304e41f4b71Sopenharmony_ci| ------ | ----------------------------------------------------------- | ---- | ----------------------------------------------------- | 305e41f4b71Sopenharmony_ci| value | [TextContentStyle](ts-appendix-enums.md#textcontentstyle10) | Yes | Polymorphic style of the text box.<br>Default value: **TextContentStyle.DEFAULT**| 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci### enableKeyboardOnFocus<sup>10+</sup> 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_cienableKeyboardOnFocus(value: boolean) 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ciSets whether to enable the input method when the component obtains focus in a way other than clicking. 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci**Parameters** 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 322e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ----------------------------------------------------------- | 323e41f4b71Sopenharmony_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**| 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci### selectionMenuHidden<sup>10+</sup> 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ciselectionMenuHidden(value: boolean) 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ciSets whether to hide the system text selection menu. 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci**Parameters** 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 338e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 339e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to hide the system text selection menu.<br>**true**: Tapping, long-pressing, double-tapping, triple-tapping, or right-clicking the text box will not trigger the system text selection menu.<br>**false**: Tapping, long-pressing, double-tapping, triple-tapping, or right-clicking the text box will trigger the system text selection menu.<br>Default value: **false**| 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci### barState<sup>10+</sup> 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_cibarState(value: BarState) 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ciSets the scrollbar display mode when the text box is editable. 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci**Parameters** 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 354e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 355e41f4b71Sopenharmony_ci| value | [BarState](ts-appendix-enums.md#barstate) | Yes | Scrollbar display mode when the text box is editable.<br>Default value: **BarState.Auto**| 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci### maxLines<sup>10+</sup> 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_cimaxLines(value: number) 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ciSets the maximum number of lines that can be displayed. When **textOverflow** is set, text is truncated if the content exceeds this limit. When **textOverflow** is not set, in inline style, the text is scrollable if the content exceeds the limit while the text box is focused; **maxLines** does not apply when the text box is not focused. In non-inline style, the text is truncated according to the number of lines. 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Parameters** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 370e41f4b71Sopenharmony_ci| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 371e41f4b71Sopenharmony_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** with the inline style; **+∞** with the non-inline style, indicating that there is no maximum number of lines<br>Value range: (0, +∞)| 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci### customKeyboard<sup>10+</sup> 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_cicustomKeyboard(value: CustomBuilder, options?: KeyboardOptions) 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ciCustom keyboard. 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ciWhen a custom keyboard is set, activating the text box opens the specified custom component, instead of the system input method. 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_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. 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ciThe custom keyboard is presented by overlaying the original screen, which is not compressed or lifted if avoid mode is not enabled or avoidance is not needed for the text box. 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ciThe custom keyboard cannot obtain the focus, but it blocks gesture events. 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ciBy default, the custom keyboard is closed when the input component loses the focus. You can also use the [TextAreaController](#textareacontroller8).[stopEditing](#stopediting10) API to close the keyboard. 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ciWhen a custom keyboard is set, the text box does not support camera input, even when the device supports. 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**Parameters** 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 398e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 399e41f4b71Sopenharmony_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.| 400e41f4b71Sopenharmony_ci| options<sup>12+</sup> | [KeyboardOptions](ts-basic-components-richeditor.md#keyboardoptions12) | No | Whether to support keyboard avoidance. | 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci### type<sup>11+</sup> 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_citype(value: TextAreaType) 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ciSets the text box type. 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 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 | [TextAreaType](#textareatype11) | Yes | Text box type.<br>Default value: **TextAreaType.Normal**| 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci### enterKeyType<sup>11+</sup> 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_cienterKeyType(value: EnterKeyType) 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ciSets the type of the Enter key. 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 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 | [EnterKeyType](ts-types.md#enterkeytype) | Yes | Type of the Enter key.<br>Default value: **EnterKeyType.NEW_LINE**| 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci### enableAutoFill<sup>12+</sup> 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_cienableAutoFill(value: boolean) 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ciSets whether to enable autofill. 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 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 | boolean | Yes | Whether to enable autofill.<br>**true**: enable<br>**false**: disable<br><br>Default value: **true**| 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci### contentType<sup>12+</sup> 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_cicontentType(contentType: ContentType) 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ciSets the content type for autofill. 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci**Parameters** 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 463e41f4b71Sopenharmony_ci| ----------- | ------------------------------------- | ---- | -------------- | 464e41f4b71Sopenharmony_ci| contentType | [ContentType](#contenttype12) | Yes | Content type for autofill.| 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci### lineHeight<sup>12+</sup> 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_cilineHeight(value: number | string | Resource) 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_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. 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 475e41f4b71Sopenharmony_ci 476e41f4b71Sopenharmony_ci**Parameters** 477e41f4b71Sopenharmony_ci 478e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 479e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ---------------- | 480e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Text line height.| 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ci### decoration<sup>12+</sup> 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_cidecoration(value: TextDecorationOptions) 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ciSets the color, type, and style of the text decorative line. 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci**Parameters** 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 495e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 496e41f4b71Sopenharmony_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>} | 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci### letterSpacing<sup>12+</sup> 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ciletterSpacing(value: number | string | Resource) 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ciSets the letter spacing for a text style. If the value specified is a percentage or 0, the default value is used. 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_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. 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci**Parameters** 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 513e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | -------------- | 514e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Letter spacing.| 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci### fontFeature<sup>12+</sup> 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_cifontFeature(value: string) 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ciSets the font feature, for example, monospaced digits. 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ciFormat: normal \| \<feature-tag-value\> 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ciFormat of **\<feature-tag-value\>**: \<string\> \[ \<integer\> \| on \| off ] 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ciThere can be multiple **\<feature-tag-value\>** values, which are separated by commas (,). 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ciFor example, the input format for monospaced clock fonts is "ss01" on. 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci**Parameters** 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 537e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- | 538e41f4b71Sopenharmony_ci| value | string | Yes | Font feature.| 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ciFor details about the supported font features, see [Font Feature List](ts-basic-components-text.md#fontfeature12). 541e41f4b71Sopenharmony_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. 542e41f4b71Sopenharmony_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/). 543e41f4b71Sopenharmony_ci### wordBreak<sup>12+</sup> 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ciwordBreak(value: WordBreak) 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ciSets the word break rule. This attribute does not take effect for the placeholder text. 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ci**Parameters** 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 556e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 557e41f4b71Sopenharmony_ci| value | [WordBreak](ts-appendix-enums.md#wordbreak11) | Yes | Word break rule.<br>Default value: **WordBreak.BREAK_WORD**| 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci> **NOTE** 560e41f4b71Sopenharmony_ci> 561e41f4b71Sopenharmony_ci> The component does not support the **clip** attribute. Therefore, setting this attribute does not affect text clipping. 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci### selectedBackgroundColor<sup>12+</sup> 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ciselectedBackgroundColor(value: ResourceColor) 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ciSets the background color of the selected text. If the opacity is not set, a 20% opacity will be used. 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci**Parameters** 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 576e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------ | 577e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Background color of the selected text.<br>By default, a 20% opacity is applied.| 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci### caretStyle<sup>12+</sup> 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_cicaretStyle(value: CaretStyle) 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ciSets the caret style. 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci**Parameters** 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 592e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ------------ | 593e41f4b71Sopenharmony_ci| value | [CaretStyle](ts-text-common.md#caretstyle10) | Yes | Caret style.| 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci### textIndent<sup>12+</sup> 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_citextIndent(value: Dimension) 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ciSets the indent of the first line text. 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci**Parameters** 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 608e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ---------------------------- | 609e41f4b71Sopenharmony_ci| value | [Dimension](ts-types.md#dimension10)| Yes | Indent of the first line text.<br>Default value: **0**| 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci### textOverflow<sup>12+</sup> 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_citextOverflow(value: TextOverflow) 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ciSets the display mode when the text is too long. 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ciIn inline style, the effect of truncating text according to **maxLines** only applies when **textOverflow** is set. 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ciText is clipped at the transition between words. To clip text in the middle of a word, set **wordBreak** to **WordBreak.BREAK_ALL**. 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ciIf **overflow** is set to **TextOverflow.None**, **TextOverflow.Clip**, or **TextOverflow.Ellipsis**, this attribute must be used with **maxLines** for the settings to take effect. **TextOverflow.None** produces the same effect as **TextOverflow.Clip**. 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets. 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci**Parameters** 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 632e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 633e41f4b71Sopenharmony_ci| value | [TextOverflow](ts-appendix-enums.md#textoverflow) | Yes | Display mode when the text is too long.<br>Default value: **TextOverflow.Clip** | 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci> **NOTE** 636e41f4b71Sopenharmony_ci> The **TextArea** component does not support the **TextOverflow.MARQUEE** mode. If this attribute is set to **TextOverflow.MARQUEE**, **TextOverflow.Clip** is used instead. 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci### minFontSize<sup>12+</sup> 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ciminFontSize(value: number | string | Resource) 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ciSets the minimum font size. 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ciFor the setting to take effect, this attribute must be used together with [maxFontSize](#maxfontsize12) and [maxLines](#maxlines10), or layout constraint settings. 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ciWhen the adaptive font size is used, the **fontSize** settings do not take effect. 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci**Parameters** 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 655e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 656e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Minimum font size.| 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci### maxFontSize<sup>12+</sup> 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_cimaxFontSize(value: number | string | Resource) 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ciSets the maximum font size. 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ciFor the setting to take effect, this attribute must be used together with [minFontSize](#minfontsize12) and [maxLines](#maxlines10), or layout constraint settings. 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ciWhen the adaptive font size is used, the **fontSize** settings do not take effect. 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci**Parameters** 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 675e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 676e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Maximum font size.| 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci### heightAdaptivePolicy<sup>12+</sup> 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ciheightAdaptivePolicy(value: TextHeightAdaptivePolicy) 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ciSets how the adaptive height is determined for the text. 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_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. 685e41f4b71Sopenharmony_ciIf the text box is in inline input style, the font size in the editing state is different from that in the non-editing state. 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_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**. 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ciIf this attribute is set to **TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST**, the layout constraints take precedence for adjusting the text height. If the resultant layout is beyond the layout constraints, the text will shrink to a font size between **minFontSize** and **maxFontSize** to respect the layout constraints. 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci**Parameters** 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 698e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 699e41f4b71Sopenharmony_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**| 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci### lineSpacing<sup>12+</sup> 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_cilineSpacing(value: LengthMetrics) 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ciSets the line spacing of the text. If the value specified is less than or equal to 0, the default value **0** is used. 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci**Parameters** 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 714e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ---------------- | 715e41f4b71Sopenharmony_ci| value | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | Yes | Line spacing. Default value: **0**| 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci### lineBreakStrategy<sup>12+</sup> 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_cilineBreakStrategy(strategy: LineBreakStrategy) 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ciSets the line break rule. This attribute takes effect when **wordBreak** is not set to **breakAll**. Hyphens are not supported. 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci**Parameters** 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 730e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------- | 731e41f4b71Sopenharmony_ci| strategy | [LineBreakStrategy](ts-appendix-enums.md#linebreakstrategy12) | Yes | Line break rule.<br>Default value: **LineBreakStrategy.GREEDY**| 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci### editMenuOptions<sup>12+</sup> 734e41f4b71Sopenharmony_ci 735e41f4b71Sopenharmony_cieditMenuOptions(editMenu: EditMenuOptions) 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ciSets the extended options of the custom context menu on selection, including the text content, icon, and callback. 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci**Parameters** 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 746e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 747e41f4b71Sopenharmony_ci| editMenu | [EditMenuOptions](ts-text-common.md#editmenuoptions) | Yes | Extended options of the custom context menu on selection.| 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci### enablePreviewText<sup>12+</sup> 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_cienablePreviewText(enable: boolean) 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ciSets whether to enable preview text. 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ciPreview text is in a temporary state and does not support text interception. As such, it does not trigger **onWillInsert**, **onDidInsert**, **onWillDelete**, or **onDidDelete** callbacks. 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**Parameters** 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 764e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------- | 765e41f4b71Sopenharmony_ci| enable | boolean | Yes | Whether to enable preview text.<br>Default value: **true**| 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci## Events 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following events are supported. 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci### onChange 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_cionChange(callback: EditableTextOnChangeCallback) 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ciCalled when the input in the text box changes. 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ci**Parameters** 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 784e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- | 785e41f4b71Sopenharmony_ci| callback | [EditableTextOnChangeCallback](ts-text-common.md#editabletextonchangecallback12) | Yes | Callback invoked when the input in the text box changes.| 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci### onEditChange<sup>10+</sup> 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_cionEditChange(callback: (isEditing: boolean) => void) 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_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. 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci**Parameters** 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 800e41f4b71Sopenharmony_ci| --------- | ------- | ---- | -------------------- | 801e41f4b71Sopenharmony_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.| 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci### onCopy<sup>8+</sup> 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_cionCopy(callback: (value: string) => void) 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ciInvoked when a copy operation is performed. 808e41f4b71Sopenharmony_ci 809e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ci**Parameters** 814e41f4b71Sopenharmony_ci 815e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 816e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- | 817e41f4b71Sopenharmony_ci| value | string | Yes | Text that is copied.| 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_ci### onCut<sup>8+</sup> 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_cionCut(callback: (value: string) => void) 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ciInvoked when a cut operation is performed. 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci**Parameters** 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 832e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- | 833e41f4b71Sopenharmony_ci| value | string | Yes | Text that is cut.| 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci### onPaste 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_cionPaste(callback: (value: string, event: PasteEvent) => void) 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ciInvoked when a paste operation is performed. 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci**Parameters** 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 848e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------------------ | ---- | ---------------------- | 849e41f4b71Sopenharmony_ci| value | string | Yes | Text to be pasted. | 850e41f4b71Sopenharmony_ci| event<sup>11+</sup> | [PasteEvent](ts-basic-components-richeditor.md#pasteevent11) | Yes | Custom paste event.| 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci### onTextSelectionChange<sup>10+</sup> 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_cionTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void) 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ciInvoked when the position of the text selection changes or when the cursor position changes during the editing state. 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**Parameters** 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 865e41f4b71Sopenharmony_ci| -------------- | ------ | ---- | --------------------------------------- | 866e41f4b71Sopenharmony_ci| selectionStart | number | Yes | Start position of the selected text. The start position of text is **0**.| 867e41f4b71Sopenharmony_ci| selectionEnd | number | Yes | End position of the selected text. | 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ci### onContentScroll<sup>10+</sup> 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_cionContentScroll(callback: (totalOffsetX: number, totalOffsetY: number) => void) 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ciCalled when the text content is scrolled. 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci**Parameters** 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 882e41f4b71Sopenharmony_ci| ------------ | ------ | ---- | ---------------------------------- | 883e41f4b71Sopenharmony_ci| totalOffsetX | number | Yes | Offset in the X coordinate of the text in the content area, in px.| 884e41f4b71Sopenharmony_ci| totalOffsetY | number | Yes | Offset in the Y coordinate of the text in the content area, in px.| 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci### onSubmit<sup>11+</sup> 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_cionSubmit(callback: (enterKey: EnterKeyType) => void) 889e41f4b71Sopenharmony_ci 890e41f4b71Sopenharmony_ciCalled when the Enter key on the keyboard is pressed. 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 893e41f4b71Sopenharmony_ci 894e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci**Parameters** 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 899e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 900e41f4b71Sopenharmony_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.| 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ci### onWillInsert<sup>12+</sup> 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_cionWillInsert(callback: Callback\<InsertValue, boolean>) 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ciCalled when text is about to be inserted. 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 909e41f4b71Sopenharmony_ci 910e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 911e41f4b71Sopenharmony_ci 912e41f4b71Sopenharmony_ci**Parameters** 913e41f4b71Sopenharmony_ci 914e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 915e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 916e41f4b71Sopenharmony_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.| 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ci### onDidInsert<sup>12+</sup> 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_cionDidInsert(callback: Callback\<InsertValue>) 921e41f4b71Sopenharmony_ci 922e41f4b71Sopenharmony_ciCalled when text is inserted. 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 927e41f4b71Sopenharmony_ci 928e41f4b71Sopenharmony_ci**Parameters** 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 931e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 932e41f4b71Sopenharmony_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.| 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci### onWillDelete<sup>12+</sup> 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_cionWillDelete(callback: Callback\<DeleteValue, boolean>) 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ciCalled when text is about to be deleted. 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci**Parameters** 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 947e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 948e41f4b71Sopenharmony_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.| 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci### onDidDelete<sup>12+</sup> 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_cionDidDelete(callback: Callback\<DeleteValue>) 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ciCalled when text is deleted. 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ci**Parameters** 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 963e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------ | 964e41f4b71Sopenharmony_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.| 965e41f4b71Sopenharmony_ci 966e41f4b71Sopenharmony_ci## TextAreaController<sup>8+</sup> 967e41f4b71Sopenharmony_ci 968e41f4b71Sopenharmony_ciInherits from [TextContentControllerBase](ts-types.md#textcontentcontrollerbase10). 969e41f4b71Sopenharmony_ci 970e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 971e41f4b71Sopenharmony_ci 972e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ci### Objects to Import 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_ci``` 977e41f4b71Sopenharmony_cicontroller: TextAreaController = new TextAreaController() 978e41f4b71Sopenharmony_ci``` 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci### constructor<sup>8+</sup> 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ciconstructor() 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ciA constructor used to create a **TextAreaController** object. 985e41f4b71Sopenharmony_ci 986e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 987e41f4b71Sopenharmony_ci 988e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci### caretPosition<sup>8+</sup> 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_cicaretPosition(value: number): void 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ciSets the position of the caret. 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 | number | Yes | Length from the start of the string to the position where the caret is located.| 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci### setTextSelection<sup>10+</sup> 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_cisetTextSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ciSets the text selection range and highlights the selected text when the component is focused. This API works only when the value of **selectionStart** is less than that of **selectionEnd**. 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| selectionStart | number | Yes | Start position of the text selection range. The start position of text in the text box is 0.<br>A value less than 0 is handled as **0**. A value greater than the maximum text length is handled as the maximum text length.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1021e41f4b71Sopenharmony_ci| selectionEnd | number | Yes | End position of the text selection range.<br>A value less than 0 is handled as the value **0**. A value greater than the maximum text length is handled as the maximum text length.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1022e41f4b71Sopenharmony_ci| options<sup>12+</sup> | [SelectionOptions](ts-types.md#selectionoptions12) | No | Configuration options for text selection.<br>Default value: **MenuPolicy.DEFAULT**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_ci> **NOTE** 1025e41f4b71Sopenharmony_ci> 1026e41f4b71Sopenharmony_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**. 1027e41f4b71Sopenharmony_ci> 1028e41f4b71Sopenharmony_ci> If the selected text contains an emoji, the emoji is selected when its start position is within the text selection range. 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci### stopEditing<sup>10+</sup> 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_cistopEditing(): void 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ciExits the editing state. 1035e41f4b71Sopenharmony_ci 1036e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci## TextAreaType<sup>11+</sup> 1041e41f4b71Sopenharmony_ci 1042e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1045e41f4b71Sopenharmony_ci 1046e41f4b71Sopenharmony_ci| Name | Value | Description| 1047e41f4b71Sopenharmony_ci| ------ | ----- | ------ | 1048e41f4b71Sopenharmony_ci| NORMAL | 0 | Normal input mode.<br>The value can contain digits, letters, underscores (_), spaces, and special characters.| 1049e41f4b71Sopenharmony_ci| NUMBER | 2 | Digit input mode. | 1050e41f4b71Sopenharmony_ci| PHONE_NUMBER | 3 | 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.| 1051e41f4b71Sopenharmony_ci| EMAIL | 5 | Email address input mode.<br>This mode accepts only digits, letters, underscores (_), dots (.), and the following special characters: ! # $ % & ' * + - / = ? ^ ` \{ \| \} ~ @ (which can only appear once)| 1052e41f4b71Sopenharmony_ci| NUMBER_DECIMAL<sup>12+</sup> | 12 | Number input mode with a decimal point.<br>The value can contain digits and one decimal point.| 1053e41f4b71Sopenharmony_ci| URL<sup>12+</sup> | 13 | URL input mode.| 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ci## ContentType<sup>12+</sup> 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ciEnumerates the content types for autofill. 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci| Name | Value | Description | 1064e41f4b71Sopenharmony_ci| -------------------------- | ---- | ------------------------------------------------------------ | 1065e41f4b71Sopenharmony_ci| USER_NAME | 0 | Username. Password Vault, when enabled, can automatically save and fill in usernames.| 1066e41f4b71Sopenharmony_ci| PASSWORD | 1 | Password. Password Vault, when enabled, can automatically save and fill in passwords.| 1067e41f4b71Sopenharmony_ci| NEW_PASSWORD | 2 | New password. Password Vault, when enabled, can automatically generate a new password. | 1068e41f4b71Sopenharmony_ci| FULL_STREET_ADDRESS | 3 | Full street address. The scenario-based autofill feature, when enabled, can automatically save and fill in full street addresses.| 1069e41f4b71Sopenharmony_ci| HOUSE_NUMBER | 4 | House number. The scenario-based autofill feature, when enabled, can automatically save and fill in house numbers.| 1070e41f4b71Sopenharmony_ci| DISTRICT_ADDRESS | 5 | District and county. The scenario-based autofill feature, when enabled, can automatically save and fill in districts and counties.| 1071e41f4b71Sopenharmony_ci| CITY_ADDRESS | 6 | City. The scenario-based autofill feature, when enabled, can automatically save and fill in cities.| 1072e41f4b71Sopenharmony_ci| PROVINCE_ADDRESS | 7 | Province. The scenario-based autofill feature, when enabled, can automatically save and fill in provinces.| 1073e41f4b71Sopenharmony_ci| COUNTRY_ADDRESS | 8 | Country. The scenario-based autofill feature, when enabled, can automatically save and fill in countries.| 1074e41f4b71Sopenharmony_ci| PERSON_FULL_NAME | 9 | Full name. The scenario-based autofill feature, when enabled, can automatically save and fill in full names.| 1075e41f4b71Sopenharmony_ci| PERSON_LAST_NAME | 10 | Last name. The scenario-based autofill feature, when enabled, can automatically save and fill in last names.| 1076e41f4b71Sopenharmony_ci| PERSON_FIRST_NAME | 11 | First name. The scenario-based autofill feature, when enabled, can automatically save and fill in first names.| 1077e41f4b71Sopenharmony_ci| PHONE_NUMBER | 12 | Phone number. The scenario-based autofill feature, when enabled, can automatically save and fill in phone numbers.| 1078e41f4b71Sopenharmony_ci| PHONE_COUNTRY_CODE | 13 | Country code. The scenario-based autofill feature, when enabled, can automatically save and fill in country codes.| 1079e41f4b71Sopenharmony_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.| 1080e41f4b71Sopenharmony_ci| EMAIL_ADDRESS | 15 | Email address. The scenario-based autofill feature, when enabled, can automatically save and fill in email addresses.| 1081e41f4b71Sopenharmony_ci| BANK_CARD_NUMBER | 16 | Bank card number. The scenario-based autofill feature, when enabled, can automatically save and fill in bank card numbers.| 1082e41f4b71Sopenharmony_ci| ID_CARD_NUMBER | 17 | ID card number. The scenario-based autofill feature, when enabled, can automatically save and fill in ID card numbers.| 1083e41f4b71Sopenharmony_ci| NICKNAME | 23 | Nickname. The scenario-based autofill feature, when enabled, can automatically save and fill in nicknames.| 1084e41f4b71Sopenharmony_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.| 1085e41f4b71Sopenharmony_ci| FORMAT_ADDRESS | 25 | Standard address. The scenario-based autofill feature, when enabled, can automatically save and fill in standard addresses.| 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci## Example 1088e41f4b71Sopenharmony_ci 1089e41f4b71Sopenharmony_ci### Example 1 1090e41f4b71Sopenharmony_ciThis example demonstrates the basic usage of **TextArea**. 1091e41f4b71Sopenharmony_ci```ts 1092e41f4b71Sopenharmony_ci// xxx.ets 1093e41f4b71Sopenharmony_ci@Entry 1094e41f4b71Sopenharmony_ci@Component 1095e41f4b71Sopenharmony_cistruct TextAreaExample { 1096e41f4b71Sopenharmony_ci @State text: string = '' 1097e41f4b71Sopenharmony_ci @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 } 1098e41f4b71Sopenharmony_ci controller: TextAreaController = new TextAreaController() 1099e41f4b71Sopenharmony_ci 1100e41f4b71Sopenharmony_ci build() { 1101e41f4b71Sopenharmony_ci Column() { 1102e41f4b71Sopenharmony_ci TextArea({ 1103e41f4b71Sopenharmony_ci text: this.text, 1104e41f4b71Sopenharmony_ci placeholder: 'The text area can hold an unlimited amount of text. input your word...', 1105e41f4b71Sopenharmony_ci controller: this.controller 1106e41f4b71Sopenharmony_ci }) 1107e41f4b71Sopenharmony_ci .placeholderFont({ size: 16, weight: 400 }) 1108e41f4b71Sopenharmony_ci .width(336) 1109e41f4b71Sopenharmony_ci .height(56) 1110e41f4b71Sopenharmony_ci .margin(20) 1111e41f4b71Sopenharmony_ci .fontSize(16) 1112e41f4b71Sopenharmony_ci .fontColor('#182431') 1113e41f4b71Sopenharmony_ci .backgroundColor('#FFFFFF') 1114e41f4b71Sopenharmony_ci .onChange((value: string) => { 1115e41f4b71Sopenharmony_ci this.text = value 1116e41f4b71Sopenharmony_ci }) 1117e41f4b71Sopenharmony_ci Text(this.text) 1118e41f4b71Sopenharmony_ci Button('Set caretPosition 1') 1119e41f4b71Sopenharmony_ci .backgroundColor('#007DFF') 1120e41f4b71Sopenharmony_ci .margin(15) 1121e41f4b71Sopenharmony_ci .onClick(() => { 1122e41f4b71Sopenharmony_ci // Move the caret to after the first entered character. 1123e41f4b71Sopenharmony_ci this.controller.caretPosition(1) 1124e41f4b71Sopenharmony_ci }) 1125e41f4b71Sopenharmony_ci Button('Get CaretOffset') 1126e41f4b71Sopenharmony_ci .backgroundColor('#007DFF') 1127e41f4b71Sopenharmony_ci .margin(15) 1128e41f4b71Sopenharmony_ci .onClick(() => { 1129e41f4b71Sopenharmony_ci this.positionInfo = this.controller.getCaretOffset() 1130e41f4b71Sopenharmony_ci }) 1131e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 1132e41f4b71Sopenharmony_ci } 1133e41f4b71Sopenharmony_ci} 1134e41f4b71Sopenharmony_ci``` 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ci 1138e41f4b71Sopenharmony_ci### Example 2 1139e41f4b71Sopenharmony_ciThis example shows how to set the **maxLength** and **showCounter** attributes. 1140e41f4b71Sopenharmony_ci```ts 1141e41f4b71Sopenharmony_ci// xxx.ets 1142e41f4b71Sopenharmony_ci@Entry 1143e41f4b71Sopenharmony_ci@Component 1144e41f4b71Sopenharmony_cistruct TextAreaExample { 1145e41f4b71Sopenharmony_ci @State text: string = 'test' 1146e41f4b71Sopenharmony_ci @State counterVisible: boolean = false 1147e41f4b71Sopenharmony_ci @State maxNumber: number = -1 1148e41f4b71Sopenharmony_ci controller: TextAreaController = new TextAreaController() 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ci build() { 1151e41f4b71Sopenharmony_ci Column() { 1152e41f4b71Sopenharmony_ci TextArea({ 1153e41f4b71Sopenharmony_ci text: this.text, 1154e41f4b71Sopenharmony_ci placeholder: 'The text area can hold an unlimited amount of text. input your word...', 1155e41f4b71Sopenharmony_ci controller: this.controller 1156e41f4b71Sopenharmony_ci }) 1157e41f4b71Sopenharmony_ci .placeholderFont({ size: 16, weight: 400 }) 1158e41f4b71Sopenharmony_ci .width(336) 1159e41f4b71Sopenharmony_ci .height(56) 1160e41f4b71Sopenharmony_ci .margin(20) 1161e41f4b71Sopenharmony_ci .fontSize(16) 1162e41f4b71Sopenharmony_ci .fontColor('#182431') 1163e41f4b71Sopenharmony_ci .maxLength(4) 1164e41f4b71Sopenharmony_ci .showCounter(true) 1165e41f4b71Sopenharmony_ci .backgroundColor('#FFFFFF') 1166e41f4b71Sopenharmony_ci .onChange((value: string) => { 1167e41f4b71Sopenharmony_ci this.text = value 1168e41f4b71Sopenharmony_ci }) 1169e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 1170e41f4b71Sopenharmony_ci } 1171e41f4b71Sopenharmony_ci} 1172e41f4b71Sopenharmony_ci``` 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci 1177e41f4b71Sopenharmony_ci### Example 3 1178e41f4b71Sopenharmony_ciThis example illustrates how to bind a custom keyboard to the **TextArea** component. 1179e41f4b71Sopenharmony_ci```ts 1180e41f4b71Sopenharmony_ci// xxx.ets 1181e41f4b71Sopenharmony_ci@Entry 1182e41f4b71Sopenharmony_ci@Component 1183e41f4b71Sopenharmony_cistruct TextAreaExample { 1184e41f4b71Sopenharmony_ci controller: TextAreaController = new TextAreaController() 1185e41f4b71Sopenharmony_ci @State inputValue: string = "" 1186e41f4b71Sopenharmony_ci 1187e41f4b71Sopenharmony_ci // Create a custom keyboard component. 1188e41f4b71Sopenharmony_ci @Builder CustomKeyboardBuilder() { 1189e41f4b71Sopenharmony_ci Column() { 1190e41f4b71Sopenharmony_ci Button('x').onClick(() => { 1191e41f4b71Sopenharmony_ci // Disable the custom keyboard. 1192e41f4b71Sopenharmony_ci this.controller.stopEditing() 1193e41f4b71Sopenharmony_ci }) 1194e41f4b71Sopenharmony_ci Grid() { 1195e41f4b71Sopenharmony_ci ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => { 1196e41f4b71Sopenharmony_ci GridItem() { 1197e41f4b71Sopenharmony_ci Button(item + "") 1198e41f4b71Sopenharmony_ci .width(110).onClick(() => { 1199e41f4b71Sopenharmony_ci this.inputValue += item 1200e41f4b71Sopenharmony_ci }) 1201e41f4b71Sopenharmony_ci } 1202e41f4b71Sopenharmony_ci }) 1203e41f4b71Sopenharmony_ci }.maxCount(3).columnsGap(10).rowsGap(10).padding(5) 1204e41f4b71Sopenharmony_ci }.backgroundColor(Color.Gray) 1205e41f4b71Sopenharmony_ci } 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci build() { 1208e41f4b71Sopenharmony_ci Column() { 1209e41f4b71Sopenharmony_ci TextArea({ controller: this.controller, text: this.inputValue}) 1210e41f4b71Sopenharmony_ci // Bind the custom keyboard. 1211e41f4b71Sopenharmony_ci .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 }) 1212e41f4b71Sopenharmony_ci .height(200) 1213e41f4b71Sopenharmony_ci } 1214e41f4b71Sopenharmony_ci } 1215e41f4b71Sopenharmony_ci} 1216e41f4b71Sopenharmony_ci``` 1217e41f4b71Sopenharmony_ci 1218e41f4b71Sopenharmony_ci 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci### Example 4 1221e41f4b71Sopenharmony_ciThis example illustrates the use of a character counter with the **TextArea** component. 1222e41f4b71Sopenharmony_ci```ts 1223e41f4b71Sopenharmony_ci// xxx.ets 1224e41f4b71Sopenharmony_ci@Entry 1225e41f4b71Sopenharmony_ci@Component 1226e41f4b71Sopenharmony_cistruct TextAreaExample { 1227e41f4b71Sopenharmony_ci @State text: string = '' 1228e41f4b71Sopenharmony_ci controller: TextAreaController = new TextAreaController() 1229e41f4b71Sopenharmony_ci 1230e41f4b71Sopenharmony_ci build() { 1231e41f4b71Sopenharmony_ci Column() { 1232e41f4b71Sopenharmony_ci TextArea({ text: this.text, controller: this.controller }) 1233e41f4b71Sopenharmony_ci .placeholderFont({ size: 16, weight: 400 }) 1234e41f4b71Sopenharmony_ci .width(336) 1235e41f4b71Sopenharmony_ci .height(56) 1236e41f4b71Sopenharmony_ci .maxLength(6) 1237e41f4b71Sopenharmony_ci .showCounter(true, { thresholdPercentage: 50, highlightBorder: true }) 1238e41f4b71Sopenharmony_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(). 1239e41f4b71Sopenharmony_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). 1240e41f4b71Sopenharmony_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. 1241e41f4b71Sopenharmony_ci .onChange((value: string) => { 1242e41f4b71Sopenharmony_ci this.text = value 1243e41f4b71Sopenharmony_ci }) 1244e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 1245e41f4b71Sopenharmony_ci } 1246e41f4b71Sopenharmony_ci} 1247e41f4b71Sopenharmony_ci``` 1248e41f4b71Sopenharmony_ci 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ci 1252e41f4b71Sopenharmony_ci### Example 5 1253e41f4b71Sopenharmony_ciThis example shows how to set the **enterKeyType** attribute. 1254e41f4b71Sopenharmony_ci```ts 1255e41f4b71Sopenharmony_ci// xxx.ets 1256e41f4b71Sopenharmony_ci@Entry 1257e41f4b71Sopenharmony_ci@Component 1258e41f4b71Sopenharmony_cistruct TextInputExample { 1259e41f4b71Sopenharmony_ci @State Text: string = '' 1260e41f4b71Sopenharmony_ci @State enterTypes: Array<EnterKeyType> = [EnterKeyType.Go, EnterKeyType.Search, EnterKeyType.Send, EnterKeyType.Done, EnterKeyType.Next, EnterKeyType.PREVIOUS, EnterKeyType.NEW_LINE] 1261e41f4b71Sopenharmony_ci @State index: number = 0 1262e41f4b71Sopenharmony_ci build() { 1263e41f4b71Sopenharmony_ci Column({ space: 20 }) { 1264e41f4b71Sopenharmony_ci TextArea({ placeholder: 'Enter user name', text: this.Text }) 1265e41f4b71Sopenharmony_ci .width(380) 1266e41f4b71Sopenharmony_ci .enterKeyType(this.enterTypes[this.index]) 1267e41f4b71Sopenharmony_ci .onChange((value: string) => { 1268e41f4b71Sopenharmony_ci this.Text = value 1269e41f4b71Sopenharmony_ci }) 1270e41f4b71Sopenharmony_ci .onSubmit((enterKey: EnterKeyType) => { 1271e41f4b71Sopenharmony_ci console.log("trigger area onsubmit" + enterKey); 1272e41f4b71Sopenharmony_ci }) 1273e41f4b71Sopenharmony_ci Button ('Change EnterKeyType').onClick () => { 1274e41f4b71Sopenharmony_ci this.index = (this.index + 1) % this.enterTypes.length; 1275e41f4b71Sopenharmony_ci }) 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ci }.width('100%') 1278e41f4b71Sopenharmony_ci } 1279e41f4b71Sopenharmony_ci} 1280e41f4b71Sopenharmony_ci``` 1281e41f4b71Sopenharmony_ci 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ci 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci### Example 6 1286e41f4b71Sopenharmony_ciThis example shows how to set the **wordBreak** attribute for the **TextArea** component. 1287e41f4b71Sopenharmony_ci 1288e41f4b71Sopenharmony_ci```ts 1289e41f4b71Sopenharmony_ci// xxx.ets 1290e41f4b71Sopenharmony_ci@Entry 1291e41f4b71Sopenharmony_ci@Component 1292e41f4b71Sopenharmony_cistruct TextAreaExample { 1293e41f4b71Sopenharmony_ci build() { 1294e41f4b71Sopenharmony_ci Column() { 1295e41f4b71Sopenharmony_ci Text("WordBreakType as NORMAL: ").fontSize(16).fontColor(0xFF0000) 1296e41f4b71Sopenharmony_ci TextArea({ 1297e41f4b71Sopenharmony_ci text: 'This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.' 1298e41f4b71Sopenharmony_ci }) 1299e41f4b71Sopenharmony_ci .fontSize(16) 1300e41f4b71Sopenharmony_ci .border({ width: 1 }) 1301e41f4b71Sopenharmony_ci .wordBreak(WordBreak.NORMAL) 1302e41f4b71Sopenharmony_ci Text ("WordBreakType as BREAK_ALL") .fontSize (16).fontColor (0xFF0000) 1303e41f4b71Sopenharmony_ci TextArea({ 1304e41f4b71Sopenharmony_ci text: 'This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.' 1305e41f4b71Sopenharmony_ci }) 1306e41f4b71Sopenharmony_ci .fontSize(16) 1307e41f4b71Sopenharmony_ci .border({ width: 1 }) 1308e41f4b71Sopenharmony_ci .wordBreak(WordBreak.BREAK_ALL) 1309e41f4b71Sopenharmony_ci Text("WordBreakType as BREAK_WORD: ").fontSize(16).fontColor(0xFF0000) 1310e41f4b71Sopenharmony_ci TextArea({ 1311e41f4b71Sopenharmony_ci text: 'This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.' 1312e41f4b71Sopenharmony_ci }) 1313e41f4b71Sopenharmony_ci .fontSize(16) 1314e41f4b71Sopenharmony_ci .border({ width: 1 }) 1315e41f4b71Sopenharmony_ci .wordBreak(WordBreak.BREAK_WORD) 1316e41f4b71Sopenharmony_ci } 1317e41f4b71Sopenharmony_ci } 1318e41f4b71Sopenharmony_ci} 1319e41f4b71Sopenharmony_ci``` 1320e41f4b71Sopenharmony_ci 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci 1323e41f4b71Sopenharmony_ci### Example 7 1324e41f4b71Sopenharmony_ci 1325e41f4b71Sopenharmony_ciThis example shows how to use the **lineHeight**, **letterSpacing**, and **decoration** attributes. 1326e41f4b71Sopenharmony_ci 1327e41f4b71Sopenharmony_ci```ts 1328e41f4b71Sopenharmony_ci// xxx.ets 1329e41f4b71Sopenharmony_ci@Entry 1330e41f4b71Sopenharmony_ci@Component 1331e41f4b71Sopenharmony_cistruct TextAreaExample { 1332e41f4b71Sopenharmony_ci build() { 1333e41f4b71Sopenharmony_ci Row() { 1334e41f4b71Sopenharmony_ci Column() { 1335e41f4b71Sopenharmony_ci Text('lineHeight').fontSize(9).fontColor(0xCCCCCC) 1336e41f4b71Sopenharmony_ci TextArea({text: 'lineHeight unset'}) 1337e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(10).margin(5) 1338e41f4b71Sopenharmony_ci TextArea({text: 'lineHeight 15'}) 1339e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(10).margin(5).lineHeight(15) 1340e41f4b71Sopenharmony_ci TextArea({text: 'lineHeight 30'}) 1341e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(10).margin(5).lineHeight(30) 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ci Text('letterSpacing').fontSize(9).fontColor(0xCCCCCC) 1344e41f4b71Sopenharmony_ci TextArea({text: 'letterSpacing 0'}) 1345e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5).letterSpacing(0) 1346e41f4b71Sopenharmony_ci TextArea({text: 'letterSpacing 3'}) 1347e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5).letterSpacing(3) 1348e41f4b71Sopenharmony_ci TextArea({text: 'letterSpacing -1'}) 1349e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5).letterSpacing(-1) 1350e41f4b71Sopenharmony_ci 1351e41f4b71Sopenharmony_ci Text('decoration').fontSize(9).fontColor(0xCCCCCC) 1352e41f4b71Sopenharmony_ci TextArea({text: 'LineThrough, Red\nsecond line'}) 1353e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5) 1354e41f4b71Sopenharmony_ci .decoration({type: TextDecorationType.LineThrough, color: Color.Red}) 1355e41f4b71Sopenharmony_ci TextArea({text: 'Overline, Red, DOTTED\nsecond line'}) 1356e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5) 1357e41f4b71Sopenharmony_ci .decoration({type: TextDecorationType.Overline, color: Color.Red, style: TextDecorationStyle.DOTTED}) 1358e41f4b71Sopenharmony_ci TextArea({text: 'Underline, Red, WAVY\nsecond line'}) 1359e41f4b71Sopenharmony_ci .border({ width: 1 }).padding(5).margin(5) 1360e41f4b71Sopenharmony_ci .decoration({type: TextDecorationType.Underline, color: Color.Red, style: TextDecorationStyle.WAVY}) 1361e41f4b71Sopenharmony_ci }.height('90%') 1362e41f4b71Sopenharmony_ci } 1363e41f4b71Sopenharmony_ci .width('90%') 1364e41f4b71Sopenharmony_ci .margin(10) 1365e41f4b71Sopenharmony_ci } 1366e41f4b71Sopenharmony_ci} 1367e41f4b71Sopenharmony_ci``` 1368e41f4b71Sopenharmony_ci 1369e41f4b71Sopenharmony_ci 1370e41f4b71Sopenharmony_ci 1371e41f4b71Sopenharmony_ci### Example 8 1372e41f4b71Sopenharmony_ciThis example shows how to set the **fontFeature** attribute, with a comparison between the ss01-enabled and ss01-disabled effects. 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci```ts 1375e41f4b71Sopenharmony_ci@Entry 1376e41f4b71Sopenharmony_ci@Component 1377e41f4b71Sopenharmony_cistruct textArea { 1378e41f4b71Sopenharmony_ci @State text1: string = 'This is ss01 on: 0123456789' 1379e41f4b71Sopenharmony_ci @State text2: string = 'This is ss01 off: 0123456789' 1380e41f4b71Sopenharmony_ci 1381e41f4b71Sopenharmony_ci build() { 1382e41f4b71Sopenharmony_ci Column(){ 1383e41f4b71Sopenharmony_ci TextArea({text: this.text1}) 1384e41f4b71Sopenharmony_ci .fontSize(20) 1385e41f4b71Sopenharmony_ci .margin({top:200}) 1386e41f4b71Sopenharmony_ci .fontFeature("\"ss01\" on") 1387e41f4b71Sopenharmony_ci TextArea({text : this.text2}) 1388e41f4b71Sopenharmony_ci .margin({top:10}) 1389e41f4b71Sopenharmony_ci .fontSize(20) 1390e41f4b71Sopenharmony_ci .fontFeature("\"ss01\" off") 1391e41f4b71Sopenharmony_ci } 1392e41f4b71Sopenharmony_ci .width("90%") 1393e41f4b71Sopenharmony_ci .margin("5%") 1394e41f4b71Sopenharmony_ci } 1395e41f4b71Sopenharmony_ci} 1396e41f4b71Sopenharmony_ci``` 1397e41f4b71Sopenharmony_ci 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_ci### Example 9 1400e41f4b71Sopenharmony_ci 1401e41f4b71Sopenharmony_ciThis example shows how to support custom keyboard avoidance. 1402e41f4b71Sopenharmony_ci 1403e41f4b71Sopenharmony_ci```ts 1404e41f4b71Sopenharmony_ci@Entry 1405e41f4b71Sopenharmony_ci@Component 1406e41f4b71Sopenharmony_cistruct TextAreaExample { 1407e41f4b71Sopenharmony_ci controller: TextAreaController = new TextAreaController() 1408e41f4b71Sopenharmony_ci @State inputValue: string = "" 1409e41f4b71Sopenharmony_ci @State height1:string|number = '80%' 1410e41f4b71Sopenharmony_ci @State height2:number = 100 1411e41f4b71Sopenharmony_ci @State supportAvoidance:boolean = true; 1412e41f4b71Sopenharmony_ci 1413e41f4b71Sopenharmony_ci // Create a custom keyboard component. 1414e41f4b71Sopenharmony_ci @Builder CustomKeyboardBuilder() { 1415e41f4b71Sopenharmony_ci Column() { 1416e41f4b71Sopenharmony_ci Row(){ 1417e41f4b71Sopenharmony_ci Button('x').onClick(() => { 1418e41f4b71Sopenharmony_ci // Disable the custom keyboard. 1419e41f4b71Sopenharmony_ci this.controller.stopEditing() 1420e41f4b71Sopenharmony_ci }).margin(10) 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 Row(){ 1438e41f4b71Sopenharmony_ci Button("20%") 1439e41f4b71Sopenharmony_ci .fontSize(24) 1440e41f4b71Sopenharmony_ci .onClick(()=>{ 1441e41f4b71Sopenharmony_ci this.height1 = "20%" 1442e41f4b71Sopenharmony_ci }) 1443e41f4b71Sopenharmony_ci Button("80%") 1444e41f4b71Sopenharmony_ci .fontSize(24) 1445e41f4b71Sopenharmony_ci .margin({left:20}) 1446e41f4b71Sopenharmony_ci .onClick(()=>{ 1447e41f4b71Sopenharmony_ci this.height1 = "80%" 1448e41f4b71Sopenharmony_ci }) 1449e41f4b71Sopenharmony_ci } 1450e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 1451e41f4b71Sopenharmony_ci .alignItems(VerticalAlign.Bottom) 1452e41f4b71Sopenharmony_ci .height(this.height1) 1453e41f4b71Sopenharmony_ci .width("100%") 1454e41f4b71Sopenharmony_ci .padding({bottom:50}) 1455e41f4b71Sopenharmony_ci TextArea({ controller: this.controller, text: this.inputValue}) 1456e41f4b71Sopenharmony_ci .height(100) 1457e41f4b71Sopenharmony_ci // Bind the custom keyboard. 1458e41f4b71Sopenharmony_ci .customKeyboard(this.CustomKeyboardBuilder(),{ supportAvoidance: this.supportAvoidance }).margin(10).border({ width: 1 }) 1459e41f4b71Sopenharmony_ci // .height(200) 1460e41f4b71Sopenharmony_ci } 1461e41f4b71Sopenharmony_ci } 1462e41f4b71Sopenharmony_ci} 1463e41f4b71Sopenharmony_ci``` 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci 1466e41f4b71Sopenharmony_ci### Example 10 1467e41f4b71Sopenharmony_ci 1468e41f4b71Sopenharmony_ciThis example shows how to set **minFontSize**, **maxFontSize**, and **heightAdaptivePolicy**. 1469e41f4b71Sopenharmony_ci 1470e41f4b71Sopenharmony_ci```ts 1471e41f4b71Sopenharmony_ci// xxx.ets 1472e41f4b71Sopenharmony_ci@Entry 1473e41f4b71Sopenharmony_ci@Component 1474e41f4b71Sopenharmony_cistruct TextAreaExample { 1475e41f4b71Sopenharmony_ci build() { 1476e41f4b71Sopenharmony_ci Row() { 1477e41f4b71Sopenharmony_ci Column() { 1478e41f4b71Sopenharmony_ci Text('heightAdaptivePolicy').fontSize(9).fontColor(0xCCCCCC) 1479e41f4b71Sopenharmony_ci TextArea({text: 'This is the text with the height adaptive policy set'}) 1480e41f4b71Sopenharmony_ci .width('80%').height(90).borderWidth(1).margin(1) 1481e41f4b71Sopenharmony_ci .minFontSize(4) 1482e41f4b71Sopenharmony_ci .maxFontSize(40) 1483e41f4b71Sopenharmony_ci .maxLines(3) 1484e41f4b71Sopenharmony_ci .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1485e41f4b71Sopenharmony_ci TextArea({text: 'This is the text with the height adaptive policy set'}) 1486e41f4b71Sopenharmony_ci .width('80%').height(90).borderWidth(1).margin(1) 1487e41f4b71Sopenharmony_ci .minFontSize(4) 1488e41f4b71Sopenharmony_ci .maxFontSize(40) 1489e41f4b71Sopenharmony_ci .maxLines(3) 1490e41f4b71Sopenharmony_ci .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1491e41f4b71Sopenharmony_ci TextArea({text: 'This is the text with the height adaptive policy set'}) 1492e41f4b71Sopenharmony_ci .width('80%').height(90).borderWidth(1).margin(1) 1493e41f4b71Sopenharmony_ci .minFontSize(4) 1494e41f4b71Sopenharmony_ci .maxFontSize(40) 1495e41f4b71Sopenharmony_ci .maxLines(3) 1496e41f4b71Sopenharmony_ci .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1497e41f4b71Sopenharmony_ci }.height('90%') 1498e41f4b71Sopenharmony_ci } 1499e41f4b71Sopenharmony_ci .width('90%') 1500e41f4b71Sopenharmony_ci .margin(10) 1501e41f4b71Sopenharmony_ci } 1502e41f4b71Sopenharmony_ci} 1503e41f4b71Sopenharmony_ci``` 1504e41f4b71Sopenharmony_ci 1505e41f4b71Sopenharmony_ci 1506e41f4b71Sopenharmony_ci 1507e41f4b71Sopenharmony_ci### Example 11 1508e41f4b71Sopenharmony_ci 1509e41f4b71Sopenharmony_ciThis example shows how to set the **lineSpacing** attribute, with a comparison of line spacing effects. 1510e41f4b71Sopenharmony_ci 1511e41f4b71Sopenharmony_ci```ts 1512e41f4b71Sopenharmony_ciimport { LengthMetrics } from '@kit.ArkUI' 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ci@Entry 1515e41f4b71Sopenharmony_ci@Component 1516e41f4b71Sopenharmony_cistruct LineSpacingExample { 1517e41f4b71Sopenharmony_ci build() { 1518e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { 1519e41f4b71Sopenharmony_ci Text('TextArea lineSpacing.').fontSize(9).fontColor(0xCCCCCC) 1520e41f4b71Sopenharmony_ci TextArea({ placeholder: 'This is the TextArea with no lineSpacing set.' }) 1521e41f4b71Sopenharmony_ci .fontSize(12) 1522e41f4b71Sopenharmony_ci TextArea({ placeholder: 'This is the TextArea with lineSpacing set to 20_px.' }) 1523e41f4b71Sopenharmony_ci .fontSize(12) 1524e41f4b71Sopenharmony_ci .lineSpacing(LengthMetrics.px(20)) 1525e41f4b71Sopenharmony_ci TextArea({ placeholder: 'This is the TextArea with lineSpacing set to 20_vp.' }) 1526e41f4b71Sopenharmony_ci .fontSize(12) 1527e41f4b71Sopenharmony_ci .lineSpacing(LengthMetrics.vp(20)) 1528e41f4b71Sopenharmony_ci TextArea({ placeholder: 'This is the TextArea with lineSpacing set to 20_fp.' }) 1529e41f4b71Sopenharmony_ci .fontSize(12) 1530e41f4b71Sopenharmony_ci .lineSpacing(LengthMetrics.fp(20)) 1531e41f4b71Sopenharmony_ci TextArea({ placeholder: 'This is the TextArea with lineSpacing set to 20_lpx.' }) 1532e41f4b71Sopenharmony_ci .fontSize(12) 1533e41f4b71Sopenharmony_ci .lineSpacing(LengthMetrics.lpx(20)) 1534e41f4b71Sopenharmony_ci TextArea({ placeholder: 'This is the TextArea with lineSpacing set to 100%.' }) 1535e41f4b71Sopenharmony_ci .fontSize(12) 1536e41f4b71Sopenharmony_ci .lineSpacing(LengthMetrics.percent(1)) 1537e41f4b71Sopenharmony_ci }.height(600).width(350).padding({ left: 35, right: 35, top: 35 }) 1538e41f4b71Sopenharmony_ci } 1539e41f4b71Sopenharmony_ci} 1540e41f4b71Sopenharmony_ci``` 1541e41f4b71Sopenharmony_ci 1542e41f4b71Sopenharmony_ci 1543e41f4b71Sopenharmony_ci 1544e41f4b71Sopenharmony_ci### Example 12 1545e41f4b71Sopenharmony_ci 1546e41f4b71Sopenharmony_ciThis example shows how to use autofill. 1547e41f4b71Sopenharmony_ci 1548e41f4b71Sopenharmony_ci```ts 1549e41f4b71Sopenharmony_ci// xxx.ets 1550e41f4b71Sopenharmony_ci@Entry 1551e41f4b71Sopenharmony_ci@Component 1552e41f4b71Sopenharmony_cistruct TextAreaExample { 1553e41f4b71Sopenharmony_ci @State text: string = '' 1554e41f4b71Sopenharmony_ci 1555e41f4b71Sopenharmony_ci build() { 1556e41f4b71Sopenharmony_ci Column() { 1557e41f4b71Sopenharmony_ci // Email address autofill. 1558e41f4b71Sopenharmony_ci TextArea({ placeholder: 'input your email...' }) 1559e41f4b71Sopenharmony_ci .width('95%') 1560e41f4b71Sopenharmony_ci .height(40) 1561e41f4b71Sopenharmony_ci .margin(20) 1562e41f4b71Sopenharmony_ci .contentType(ContentType.EMAIL_ADDRESS) 1563e41f4b71Sopenharmony_ci .enableAutoFill(true) 1564e41f4b71Sopenharmony_ci .maxLength(20) 1565e41f4b71Sopenharmony_ci // Full street address autofill. 1566e41f4b71Sopenharmony_ci TextArea({ placeholder: 'input your street address...' }) 1567e41f4b71Sopenharmony_ci .width('95%') 1568e41f4b71Sopenharmony_ci .height(40) 1569e41f4b71Sopenharmony_ci .margin(20) 1570e41f4b71Sopenharmony_ci .contentType(ContentType.FULL_STREET_ADDRESS) 1571e41f4b71Sopenharmony_ci .enableAutoFill(true) 1572e41f4b71Sopenharmony_ci .maxLength(20) 1573e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 1574e41f4b71Sopenharmony_ci } 1575e41f4b71Sopenharmony_ci} 1576e41f4b71Sopenharmony_ci``` 1577e41f4b71Sopenharmony_ci 1578e41f4b71Sopenharmony_ci 1579e41f4b71Sopenharmony_ci 1580e41f4b71Sopenharmony_ci### Example 13 1581e41f4b71Sopenharmony_ci 1582e41f4b71Sopenharmony_ciThis example shows how to set the **lineBreakStrategy** attribute, with a comparison of line break rules. 1583e41f4b71Sopenharmony_ci 1584e41f4b71Sopenharmony_ci```ts 1585e41f4b71Sopenharmony_ci@Entry 1586e41f4b71Sopenharmony_ci@Component 1587e41f4b71Sopenharmony_cistruct TextExample1 { 1588e41f4b71Sopenharmony_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" + 1589e41f4b71Sopenharmony_ci "The built-in components include buttons radio buttonsprogress indicators and text You can set the rendering effectof thesecomponents in method chaining mode," + 1590e41f4b71Sopenharmony_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."; 1591e41f4b71Sopenharmony_ci 1592e41f4b71Sopenharmony_ci build() { 1593e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { 1594e41f4b71Sopenharmony_ci Text('LineBreakStrategy.GREEDY').fontSize(9).fontColor(0xCCCCCC).width('90%').padding(10) 1595e41f4b71Sopenharmony_ci TextArea({text: this.message1}) 1596e41f4b71Sopenharmony_ci .fontSize(12) 1597e41f4b71Sopenharmony_ci .border({ width: 1 }) 1598e41f4b71Sopenharmony_ci .padding(10) 1599e41f4b71Sopenharmony_ci .width('100%') 1600e41f4b71Sopenharmony_ci .lineBreakStrategy(LineBreakStrategy.GREEDY) 1601e41f4b71Sopenharmony_ci Text('LineBreakStrategy.HIGH_QUALITY').fontSize(9).fontColor(0xCCCCCC).width('90%').padding(10) 1602e41f4b71Sopenharmony_ci TextArea({text: this.message1}) 1603e41f4b71Sopenharmony_ci .fontSize(12) 1604e41f4b71Sopenharmony_ci .border({ width: 1 }) 1605e41f4b71Sopenharmony_ci .padding(10) 1606e41f4b71Sopenharmony_ci .width('100%') 1607e41f4b71Sopenharmony_ci .lineBreakStrategy(LineBreakStrategy.HIGH_QUALITY) 1608e41f4b71Sopenharmony_ci Text('LineBreakStrategy.BALANCED').fontSize(9).fontColor(0xCCCCCC).width('90%').padding(10) 1609e41f4b71Sopenharmony_ci TextArea({text: this.message1}) 1610e41f4b71Sopenharmony_ci .fontSize(12) 1611e41f4b71Sopenharmony_ci .border({ width: 1 }) 1612e41f4b71Sopenharmony_ci .padding(10) 1613e41f4b71Sopenharmony_ci .width('100%') 1614e41f4b71Sopenharmony_ci .lineBreakStrategy(LineBreakStrategy.BALANCED) 1615e41f4b71Sopenharmony_ci }.height(700).width(370).padding({ left: 35, right: 35, top: 35 }) 1616e41f4b71Sopenharmony_ci } 1617e41f4b71Sopenharmony_ci} 1618e41f4b71Sopenharmony_ci``` 1619e41f4b71Sopenharmony_ci 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ci 1622e41f4b71Sopenharmony_ci### Example 14 1623e41f4b71Sopenharmony_ci 1624e41f4b71Sopenharmony_ciThis example shows how to use the insert and delete callbacks. 1625e41f4b71Sopenharmony_ci 1626e41f4b71Sopenharmony_ci```ts 1627e41f4b71Sopenharmony_ci// xxx.ets 1628e41f4b71Sopenharmony_ci@Entry 1629e41f4b71Sopenharmony_ci@Component 1630e41f4b71Sopenharmony_cistruct TextAreaExample { 1631e41f4b71Sopenharmony_ci @State insertValue: string = "" 1632e41f4b71Sopenharmony_ci @State deleteValue: string = "" 1633e41f4b71Sopenharmony_ci @State insertOffset: number = 0 1634e41f4b71Sopenharmony_ci @State deleteOffset: number = 0 1635e41f4b71Sopenharmony_ci @State deleteDirection: number = 0 1636e41f4b71Sopenharmony_ci 1637e41f4b71Sopenharmony_ci build() { 1638e41f4b71Sopenharmony_ci Row() { 1639e41f4b71Sopenharmony_ci Column() { 1640e41f4b71Sopenharmony_ci TextArea({ text: "Insert callbacks" }) 1641e41f4b71Sopenharmony_ci .width(300) 1642e41f4b71Sopenharmony_ci .height(60) 1643e41f4b71Sopenharmony_ci .onWillInsert((info: InsertValue) => { 1644e41f4b71Sopenharmony_ci this.insertValue = info.insertValue 1645e41f4b71Sopenharmony_ci return true; 1646e41f4b71Sopenharmony_ci }) 1647e41f4b71Sopenharmony_ci .onDidInsert((info: InsertValue) => { 1648e41f4b71Sopenharmony_ci this.insertOffset = info.insertOffset 1649e41f4b71Sopenharmony_ci }) 1650e41f4b71Sopenharmony_ci 1651e41f4b71Sopenharmony_ci Text("insertValue:" + this.insertValue + " insertOffset:" + this.insertOffset).height(30) 1652e41f4b71Sopenharmony_ci 1653e41f4b71Sopenharmony_ci TextArea({ text: "Delete callbacks" }) 1654e41f4b71Sopenharmony_ci .width(300) 1655e41f4b71Sopenharmony_ci .height(60) 1656e41f4b71Sopenharmony_ci .onWillDelete((info: DeleteValue) => { 1657e41f4b71Sopenharmony_ci this.deleteValue = info.deleteValue 1658e41f4b71Sopenharmony_ci info.direction 1659e41f4b71Sopenharmony_ci return true; 1660e41f4b71Sopenharmony_ci }) 1661e41f4b71Sopenharmony_ci .onDidDelete((info: DeleteValue) => { 1662e41f4b71Sopenharmony_ci this.deleteOffset = info.deleteOffset 1663e41f4b71Sopenharmony_ci this.deleteDirection = info.direction 1664e41f4b71Sopenharmony_ci }) 1665e41f4b71Sopenharmony_ci 1666e41f4b71Sopenharmony_ci Text("deleteValue:" + this.deleteValue + " deleteOffset:" + this.deleteOffset).height(30) 1667e41f4b71Sopenharmony_ci Text("deleteDirection:" + (this.deleteDirection == 0 ? "BACKWARD" : "FORWARD")).height(30) 1668e41f4b71Sopenharmony_ci 1669e41f4b71Sopenharmony_ci }.width('100%') 1670e41f4b71Sopenharmony_ci } 1671e41f4b71Sopenharmony_ci .height('100%') 1672e41f4b71Sopenharmony_ci } 1673e41f4b71Sopenharmony_ci} 1674e41f4b71Sopenharmony_ci``` 1675e41f4b71Sopenharmony_ci 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci 1678e41f4b71Sopenharmony_ci### Example 15 1679e41f4b71Sopenharmony_ci 1680e41f4b71Sopenharmony_ciThis example shows how to set **editMenuOptions**. 1681e41f4b71Sopenharmony_ci 1682e41f4b71Sopenharmony_ci```ts 1683e41f4b71Sopenharmony_ci// xxx.ets 1684e41f4b71Sopenharmony_ci@Entry 1685e41f4b71Sopenharmony_ci@Component 1686e41f4b71Sopenharmony_cistruct TextAreaExample { 1687e41f4b71Sopenharmony_ci @State text: string = 'TextArea editMenuOptions' 1688e41f4b71Sopenharmony_ci 1689e41f4b71Sopenharmony_ci onCreateMenu(menuItems: Array<TextMenuItem>) { 1690e41f4b71Sopenharmony_ci menuItems.forEach((value, index) => { 1691e41f4b71Sopenharmony_ci value.icon = $r('app.media.startIcon') 1692e41f4b71Sopenharmony_ci if (value.id.equals(TextMenuItemId.COPY)) { 1693e41f4b71Sopenharmony_ci value.content = "Copy" 1694e41f4b71Sopenharmony_ci } 1695e41f4b71Sopenharmony_ci if (value.id.equals(TextMenuItemId.SELECT_ALL)) { 1696e41f4b71Sopenharmony_ci value.content = "Select All" 1697e41f4b71Sopenharmony_ci } 1698e41f4b71Sopenharmony_ci }) 1699e41f4b71Sopenharmony_ci let item1: TextMenuItem = { 1700e41f4b71Sopenharmony_ci content: 'Custom 1', 1701e41f4b71Sopenharmony_ci icon: $r('app.media.startIcon'), 1702e41f4b71Sopenharmony_ci id: TextMenuItemId.of('Custom 1'), 1703e41f4b71Sopenharmony_ci } 1704e41f4b71Sopenharmony_ci let item2: TextMenuItem = { 1705e41f4b71Sopenharmony_ci content: 'Custom 2', 1706e41f4b71Sopenharmony_ci id: TextMenuItemId.of('Custom 2'), 1707e41f4b71Sopenharmony_ci icon: $r('app.media.startIcon'), 1708e41f4b71Sopenharmony_ci } 1709e41f4b71Sopenharmony_ci menuItems.push(item1) 1710e41f4b71Sopenharmony_ci menuItems.unshift(item2) 1711e41f4b71Sopenharmony_ci return menuItems 1712e41f4b71Sopenharmony_ci } 1713e41f4b71Sopenharmony_ci 1714e41f4b71Sopenharmony_ci build() { 1715e41f4b71Sopenharmony_ci Column() { 1716e41f4b71Sopenharmony_ci TextArea({ text: this.text }) 1717e41f4b71Sopenharmony_ci .width('95%') 1718e41f4b71Sopenharmony_ci .height(56) 1719e41f4b71Sopenharmony_ci .editMenuOptions({ 1720e41f4b71Sopenharmony_ci onCreateMenu: this.onCreateMenu, onMenuItemClick: (menuItem: TextMenuItem, textRange: TextRange) => { 1721e41f4b71Sopenharmony_ci if (menuItem.id.equals(TextMenuItemId.of("custom2"))) { 1722e41f4b71Sopenharmony_ci console.log("Intercept id: custom2 start:" + textRange.start + "; end:" + textRange.end) 1723e41f4b71Sopenharmony_ci return true; 1724e41f4b71Sopenharmony_ci } 1725e41f4b71Sopenharmony_ci if (menuItem.id.equals(TextMenuItemId.COPY)) { 1726e41f4b71Sopenharmony_ci console.log("Intercept COPY start:" + textRange.start + "; end:" + textRange.end) 1727e41f4b71Sopenharmony_ci return true; 1728e41f4b71Sopenharmony_ci } 1729e41f4b71Sopenharmony_ci if (menuItem.id.equals(TextMenuItemId.SELECT_ALL)) { 1730e41f4b71Sopenharmony_ci console.log("Do not intercept SELECT_ALL start:" + textRange.start + "; end:" + textRange.end) 1731e41f4b71Sopenharmony_ci return false; 1732e41f4b71Sopenharmony_ci } 1733e41f4b71Sopenharmony_ci return false; 1734e41f4b71Sopenharmony_ci } 1735e41f4b71Sopenharmony_ci }) 1736e41f4b71Sopenharmony_ci .margin({ top: 100 }) 1737e41f4b71Sopenharmony_ci } 1738e41f4b71Sopenharmony_ci .width("90%") 1739e41f4b71Sopenharmony_ci .margin("5%") 1740e41f4b71Sopenharmony_ci } 1741e41f4b71Sopenharmony_ci} 1742e41f4b71Sopenharmony_ci``` 1743e41f4b71Sopenharmony_ci 1744e41f4b71Sopenharmony_ci 1745