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