1#  Search
2
3The **Search** component provides an area for users to enter search queries.
4
5> **NOTE**
6>
7> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8
9## Child Components
10
11Not supported
12
13## APIs
14
15Search(options?: { value?: string, placeholder?: ResourceStr, icon?: string, controller?: SearchController })
16
17**Atomic service API**: This API can be used in atomic services since API version 11.
18
19**System capability**: SystemCapability.ArkUI.ArkUI.Full
20
21**Parameters**
22
23| Name     | Type        | Mandatory| Description       |
24| ----------- | ------------- | ---- | ------------- |
25| value       | string                                               | No  | Text input in the search text box.<br>Since API version 10, this parameter supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).|
26| placeholder | [ResourceStr](ts-types.md#resourcestr) | No  | Text displayed when there is no input.                                    |
27| icon        | string                                               | No  | Path to the search icon. By default, the system search icon is used.<br>**NOTE**<br>The icon data source can be a local or online image.<br>- The supported formats include PNG, JPG, BMP, SVG, GIF, pixelmap, and HEIF.<br>- The Base64 string is supported in the following format: data:image/[png\|jpeg\|bmp\|webp\|heif];base64,[base64 data], where *[base64 data]* is a Base64 string.<br>If this attribute and the **searchIcon** attribute are both set, the **searchIcon** attribute takes precedence.|
28| controller  | [SearchController](#searchcontroller) | No  | Controller of the **Search** component.                                      |
29
30## Attributes
31
32In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
33
34### searchButton
35
36searchButton(value: string, option?: SearchButtonOptions)
37
38Sets the text on the search button located next to the search text box.
39
40Clicking the search button triggers both **onSubmit** and **onClick** callbacks.
41
42**Atomic service API**: This API can be used in atomic services since API version 11.
43
44**System capability**: SystemCapability.ArkUI.ArkUI.Full
45
46**Parameters**
47
48| Name| Type                                                 | Mandatory| Description                        |
49| ------ | ----------------------------------------------------- | ---- | ---------------------------- |
50| value  | string                                                | Yes  | Text on the search button located next to the search text box.|
51| option | [SearchButtonOptions](#searchbuttonoptions10) | No  | Font of the search text box.<br>Default value:<br>{<br>fontSize: '16fp',<br>fontColor: '#ff3f97e9'<br>}         |
52
53### placeholderColor
54
55placeholderColor(value: ResourceColor)
56
57Sets the placeholder text color.
58
59**Atomic service API**: This API can be used in atomic services since API version 11.
60
61**System capability**: SystemCapability.ArkUI.ArkUI.Full
62
63**Parameters**
64
65| Name| Type                                      | Mandatory| Description                                            |
66| ------ | ------------------------------------------ | ---- | ------------------------------------------------ |
67| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Placeholder text color.<br>Default value: **'#99182431'**|
68
69### placeholderFont
70
71placeholderFont(value?: Font)
72
73Sets 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.
74
75**Atomic service API**: This API can be used in atomic services since API version 11.
76
77**System capability**: SystemCapability.ArkUI.ArkUI.Full
78
79**Parameters**
80
81| Name| Type                    | Mandatory| Description                 |
82| ------ | ------------------------ | ---- | --------------------- |
83| value  | [Font](ts-types.md#font) | No  | Placeholder text style.|
84
85### textFont
86
87textFont(value?: Font)
88
89Sets the style of the text entered in the search box, including the font size, font width, font family, and font style. Currently, only the default font family is supported.
90
91**Atomic service API**: This API can be used in atomic services since API version 11.
92
93**System capability**: SystemCapability.ArkUI.ArkUI.Full
94
95**Parameters**
96
97| Name| Type                    | Mandatory| Description                  |
98| ------ | ------------------------ | ---- | ---------------------- |
99| value  | [Font](ts-types.md#font) | No  | Text font of the search text box.|
100
101### textAlign<sup>9+</sup>
102
103textAlign(value: TextAlign)
104
105Sets the text alignment mode in the search text box. Currently, the following alignment modes are supported: **Start**, **Center**, and **End**.
106
107**Atomic service API**: This API can be used in atomic services since API version 11.
108
109**System capability**: SystemCapability.ArkUI.ArkUI.Full
110
111**Parameters**
112
113| Name| Type                                       | Mandatory| Description                                                  |
114| ------ | ------------------------------------------- | ---- | ------------------------------------------------------ |
115| value  | [TextAlign](ts-appendix-enums.md#textalign) | Yes  | Text alignment mode in the search text box.<br>Default value: **TextAlign.Start**|
116
117### copyOption<sup>9+</sup>
118
119copyOption(value: CopyOptions)
120
121Sets whether copy and paste is allowed. If this attribute is set to **CopyOptions.None**, the text can be pasted, but copy, cut, or AI-powered writing is not allowed.
122
123Dragging is not allowed when **CopyOptions.None** is set.
124
125**Atomic service API**: This API can be used in atomic services since API version 11.
126
127**System capability**: SystemCapability.ArkUI.ArkUI.Full
128
129**Parameters**
130
131| Name| Type                                            | Mandatory| Description                                                        |
132| ------ | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
133| value  | [CopyOptions](ts-appendix-enums.md#copyoptions9) | Yes  | Whether copy and paste is allowed.<br>Default value: **CopyOptions.LocalDevice**|
134
135### searchIcon<sup>10+</sup>
136
137searchIcon(value: IconOptions | SymbolGlyphModifier)
138
139Sets the style of the search icon on the left.
140
141**Atomic service API**: This API can be used in atomic services since API version 11.
142
143**System capability**: SystemCapability.ArkUI.ArkUI.Full
144
145**Parameters**
146
147| Name| Type                                 | Mandatory| Description              |
148| ------ | ------------------------------------- | ---- | ------------------ |
149| value  | [IconOptions](#iconoptions10) \| [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | Yes  | Style of the search icon on the left.<!--RP1--><br>Default value in light mode:<br>{<br>size: '16vp',<br>color: '#99182431',<br>src: ' '<br>}<br>Default value in dark mode:<br>{<br>size: '16vp',<br>color: '#99ffffff',<br>src: ' '<br>} <!--RP1End-->|
150
151### cancelButton<sup>10+</sup>
152
153cancelButton(value: CancelButtonOptions | CancelButtonSymbolOptions)
154
155Sets the style of the Cancel button on the right.
156
157**Atomic service API**: This API can be used in atomic services since API version 11.
158
159**System capability**: SystemCapability.ArkUI.ArkUI.Full
160
161**Parameters**
162
163| Name| Type                                                        | Mandatory| Description                                                        |
164| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
165| value  | [CancelButtonOptions](#cancelbuttonoptions12) \| [CancelButtonSymbolOptions](#cancelbuttonsymboloptions12) | Yes  | Style of the Cancel button on the right.<br>Default value:<br>{<br>style: CancelButtonStyle.INPUT,<br>icon: {<br>size: '16vp',<br>color: '#99ffffff',<br>src: ' '<br>}<br>}<br>When **style** is set to **CancelButtonStyle.CONSTANT**, the Cancel button is always displayed.|
166
167### fontColor<sup>10+</sup>
168
169fontColor(value: ResourceColor)
170
171Sets the font color of the input text. [Universal text attributes](ts-universal-attributes-text-style.md) **fontSize**, **fontStyle**, **fontWeight**, and **fontFamily** are set in the [textFont](#textfont) attribute.
172
173**Atomic service API**: This API can be used in atomic services since API version 11.
174
175**System capability**: SystemCapability.ArkUI.ArkUI.Full
176
177**Parameters**
178
179| Name| Type                                      | Mandatory| Description                                           |
180| ------ | ------------------------------------------ | ---- | ----------------------------------------------- |
181| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Font color of the input text.<br>Default value: **'#FF182431'**|
182
183### caretStyle<sup>10+</sup>
184
185caretStyle(value: CaretStyle)
186
187Sets the caret style.
188
189**Atomic service API**: This API can be used in atomic services since API version 11.
190
191**System capability**: SystemCapability.ArkUI.ArkUI.Full
192
193**Parameters**
194
195| Name| Type                               | Mandatory| Description                                                        |
196| ------ | ----------------------------------- | ---- | ------------------------------------------------------------ |
197| value  | [CaretStyle](ts-text-common.md#caretstyle10) | Yes  | Caret style.<br>Default value:<br>{<br>width: '1.5vp',<br>color: '#007DFF'<br>} |
198
199>  **NOTE**
200>   Since API version 12, this API can be used to set the text handle color, which is the same as the caret color.
201
202### enableKeyboardOnFocus<sup>10+</sup>
203
204enableKeyboardOnFocus(value: boolean)
205
206Sets whether to enable the input method when the **Search** component obtains focus in a way other than clicking.
207
208
209
210**Atomic service API**: This API can be used in atomic services since API version 11.
211
212**System capability**: SystemCapability.ArkUI.ArkUI.Full
213
214**Parameters**
215
216| Name| Type   | Mandatory| Description                                           |
217| ------ | ------- | ---- | ----------------------------------------------- |
218| value  | boolean | Yes  | Whether to enable the input method when the component obtains focus in a way other than clicking.<br>Default value: **true**|
219
220### selectionMenuHidden<sup>10+</sup>
221
222selectionMenuHidden(value: boolean)
223
224Sets whether to hide the system text selection menu.
225
226**Atomic service API**: This API can be used in atomic services since API version 11.
227
228**System capability**: SystemCapability.ArkUI.ArkUI.Full
229
230**Parameters**
231
232| Name| Type   | Mandatory| Description                                                        |
233| ------ | ------- | ---- | ------------------------------------------------------------ |
234| 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**|
235
236### customKeyboard<sup>10+</sup>
237
238customKeyboard(value: CustomBuilder, options?: KeyboardOptions)
239
240Sets the custom keyboard.
241
242When a custom keyboard is set, activating the text box opens the specified custom component, instead of the system input method.
243
244The 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.
245
246The custom keyboard is presented by overlaying the original screen. It is not compressed or lifted if avoid mode is not enabled or avoidance is not needed for the text box.
247
248The custom keyboard cannot obtain the focus, but it blocks gesture events.
249
250By default, the custom keyboard is closed when the input component loses the focus. You can also use the [stopEditing](#stopediting10) API to close the keyboard.
251
252When a custom keyboard is set, the text box does not support camera input, even when the device supports.
253
254When setting a custom keyboard, you can bind the [onKeyPrelme](ts-universal-events-key.md#onkeypreime12) event to prevent input from the physical keyboard.
255
256**Atomic service API**: This API can be used in atomic services since API version 11.
257
258**System capability**: SystemCapability.ArkUI.ArkUI.Full
259
260**Parameters**
261
262| Name               | Type                                       | Mandatory| Description                            |
263| --------------------- | ------------------------------------------- | ---- | -------------------------------- |
264| value                 | [CustomBuilder](ts-types.md#custombuilder8) | Yes  | Custom keyboard.                    |
265| options<sup>12+</sup> | [KeyboardOptions](ts-basic-components-richeditor.md#keyboardoptions12)       | No  | Whether to support keyboard avoidance.|
266
267### type<sup>11+</sup>
268
269type(value: SearchType)
270
271Sets the text box type.
272
273<br>**Atomic service API**: This API can be used in atomic services since API version 12.
274
275**System capability**: SystemCapability.ArkUI.ArkUI.Full
276
277**Parameters**
278
279| Name| Type                               | Mandatory| Description                       |
280| ------ | ----------------------------------- | ---- | -------------------------- |
281| value  | [SearchType](#searchtype11) | Yes  | Text box type.<br>Default value: **SearchType.Normal**|
282
283### maxLength<sup>11+</sup>
284
285maxLength(value: number)
286
287Sets the maximum number of characters for text input. By default, there is no maximum number of characters. When the maximum number is reached, no more characters can be entered.
288
289**Atomic service API**: This API can be used in atomic services since API version 12.
290
291**System capability**: SystemCapability.ArkUI.ArkUI.Full
292
293**Parameters**
294
295| Name| Type                               | Mandatory| Description                  |
296| ------ | ----------------------------------- | ---- | ---------------------- |
297| value  | number | Yes  | Maximum number of characters for text input.|
298
299### enterKeyType<sup>12+</sup>
300
301enterKeyType(value: EnterKeyType)
302
303Sets the type of the Enter key.
304
305**Atomic service API**: This API can be used in atomic services since API version 12.
306
307**System capability**: SystemCapability.ArkUI.ArkUI.Full
308
309**Parameters**
310
311| Name| Type                                            | Mandatory| Description                                              |
312| ------ | ------------------------------------------------ | ---- | -------------------------------------------------- |
313| value  | [EnterKeyType](ts-basic-components-textinput.md#enterkeytype) | Yes  | Type of the Enter key.<br>Default value: **EnterKeyType.Search**|
314
315### lineHeight<sup>12+</sup>
316
317lineHeight(value: number | string | Resource)
318
319Sets 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.
320
321**Atomic service API**: This API can be used in atomic services since API version 12.
322
323**System capability**: SystemCapability.ArkUI.ArkUI.Full
324
325**Parameters**
326
327| Name| Type                                                        | Mandatory| Description            |
328| ------ | ------------------------------------------------------------ | ---- | ---------------- |
329| value  | number \| string \| [Resource](ts-types.md#resource) | Yes  | Text line height.|
330
331### decoration<sup>12+</sup>
332
333decoration(value: TextDecorationOptions)
334
335Sets the color, type, and style of the text decorative line.
336
337**Atomic service API**: This API can be used in atomic services since API version 12.
338
339**System capability**: SystemCapability.ArkUI.ArkUI.Full
340
341**Parameters**
342
343| Name| Type                                                        | Mandatory| Description                                                        |
344| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
345| 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>} |
346
347### letterSpacing<sup>12+</sup>
348
349letterSpacing(value: number | string | Resource)
350
351Sets the letter spacing for a text style. If the value specified is a percentage or 0, the default value is used.
352
353If 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.
354
355**Atomic service API**: This API can be used in atomic services since API version 12.
356
357**System capability**: SystemCapability.ArkUI.ArkUI.Full
358
359**Parameters**
360
361| Name| Type                      | Mandatory| Description          |
362| ------ | -------------------------- | ---- | -------------- |
363| value  | number \| string \| [Resource](ts-types.md#resource) | Yes  | Letter spacing.|
364
365### fontFeature<sup>12+</sup>
366
367fontFeature(value: string)
368
369Sets the font feature, for example, monospaced digits.
370
371Format: normal \| \<feature-tag-value\>
372
373Format of **\<feature-tag-value\>**: \<string\> \[ \<integer\> \| on \| off ]
374
375There can be multiple **\<feature-tag-value\>** values, which are separated by commas (,).
376
377For example, the input format for monospaced clock fonts is "ss01" on.
378
379**Atomic service API**: This API can be used in atomic services since API version 12.
380
381**System capability**: SystemCapability.ArkUI.ArkUI.Full
382
383**Parameters**
384
385| Name| Type  | Mandatory| Description          |
386| ------ | ------ | ---- | -------------- |
387| value  | string | Yes  | Font feature.|
388
389For details about the supported font features, see [Font Feature List](ts-basic-components-text.md#fontfeature12).
390Font 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.
391For 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/).
392
393### selectedBackgroundColor<sup>12+</sup>
394
395selectedBackgroundColor(value: ResourceColor)
396
397Sets the background color of the selected text. If the opacity is not set, a 20% opacity will be used.
398
399**Atomic service API**: This API can be used in atomic services since API version 12.
400
401**System capability**: SystemCapability.ArkUI.ArkUI.Full
402
403**Parameters**
404
405| Name| Type                                      | Mandatory| Description                                      |
406| ------ | ------------------------------------------ | ---- | ------------------------------------------ |
407| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Background color of the selected text.<br>By default, a 20% opacity is applied.|
408
409### inputFilter<sup>12+</sup>
410
411inputFilter(value: ResourceStr, error?:  Callback< string >)
412
413Sets 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.
414
415If **inputFilter** is set and the entered characters are not null, the filtering effect attached to the text box type (specified through the **type** attribute) does not take effect.
416
417**Atomic service API**: This API can be used in atomic services since API version 12.
418
419**System capability**: SystemCapability.ArkUI.ArkUI.Full
420
421**Parameters**
422
423| Name| Type                                  | Mandatory| Description                              |
424| ------ | -------------------------------------- | ---- | ---------------------------------- |
425| value  | [ResourceStr](ts-types.md#resourcestr) | Yes  | Regular expression.                      |
426| error  |  Callback< string >     | No  | Filtered-out content to return when regular expression matching fails.|
427
428### textIndent<sup>12+</sup>
429
430textIndent(value: Dimension)
431
432Sets the indent of the first line text.
433
434**Atomic service API**: This API can be used in atomic services since API version 12.
435
436**System capability**: SystemCapability.ArkUI.ArkUI.Full
437
438**Parameters**
439
440| Name| Type                                | Mandatory| Description                        |
441| ------ | ----------------------------------- | ---- | ---------------------------- |
442| value  | [Dimension](ts-types.md#dimension10)| Yes  | Indent of the first line text.<br>Default value: **0**  |
443
444### minFontSize<sup>12+</sup>
445
446minFontSize(value: number | string | Resource)
447
448Sets the minimum font size.
449
450For the setting to take effect, this attribute must be used together with [maxFontSize](#maxfontsize12) or layout constraint settings.
451
452When the adaptive font size is used, the **fontSize** settings do not take effect.
453
454**Atomic service API**: This API can be used in atomic services since API version 12.
455
456**System capability**: SystemCapability.ArkUI.ArkUI.Full
457
458**Parameters**
459
460| Name| Type                                                        | Mandatory| Description              |
461| ------ | ------------------------------------------------------------ | ---- | ------------------ |
462| value  | number \| string \| [Resource](ts-types.md#resource) | Yes  | Minimum font size.|
463
464### maxFontSize<sup>12+</sup>
465
466maxFontSize(value: number | string | Resource)
467
468Sets the maximum font size.
469
470For the setting to take effect, this attribute must be used together with [minFontSize](#minfontsize12) or layout constraint settings.
471
472When the adaptive font size is used, the **fontSize** settings do not take effect.
473
474**Atomic service API**: This API can be used in atomic services since API version 12.
475
476**System capability**: SystemCapability.ArkUI.ArkUI.Full
477
478**Parameters**
479
480| Name| Type                                                        | Mandatory| Description              |
481| ------ | ------------------------------------------------------------ | ---- | ------------------ |
482| value  | number \| string \| [Resource](ts-types.md#resource) | Yes  | Maximum font size.|
483
484### editMenuOptions<sup>12+</sup>
485
486editMenuOptions(editMenu: EditMenuOptions)
487
488Sets the extended options of the custom context menu on selection, including the text content, icon, and callback.
489
490**Atomic service API**: This API can be used in atomic services since API version 12.
491
492**System capability**: SystemCapability.ArkUI.ArkUI.Full
493
494**Parameters**
495
496| Name| Type                                         | Mandatory| Description                                         |
497| ------ | --------------------------------------------- | ---- | --------------------------------------------- |
498| editMenu  | [EditMenuOptions](ts-text-common.md#editmenuoptions) | Yes  | Extended options of the custom context menu on selection.|
499
500### enablePreviewText<sup>12+</sup>
501
502enablePreviewText(enable: boolean)
503
504Sets whether to enable preview text.
505
506Preview text is in a temporary state and does not support text interception. As such, it does not trigger **onWillInsert**, **onDidInsert**, **onWillDelete**, or **onDidDelete** callbacks.
507
508**Atomic service API**: This API can be used in atomic services since API version 12.
509
510**System capability**: SystemCapability.ArkUI.ArkUI.Full
511
512**Parameters**
513
514| Name| Type   | Mandatory| Description                              |
515| ------ | ------- | ---- | ---------------------------------- |
516| enable | boolean | Yes  | Whether to enable preview text.<br>Default value: **true**|
517
518>  **NOTE**
519>
520>  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:
521> ```json
522> "metadata": [
523>  {
524>     "name": "can_preview_text",
525>     "value": "true",
526>  }
527> ]
528> ```
529
530### enableHapticFeedback<sup>13+</sup>
531
532enableHapticFeedback(isEnabled: boolean)
533
534Specifies whether to enable haptic feedback.
535
536**Atomic service API**: This API can be used in atomic services since API version 13.
537
538**System capability**: SystemCapability.ArkUI.ArkUI.Full
539
540**Parameters**
541
542| Name| Type   | Mandatory| Description                              |
543| ------ | ------- | ---- | ---------------------------------- |
544| isEnabled | boolean | Yes  | Whether to enable haptic feedback.<br>Default value: **true**|
545
546>  **NOTE**
547>
548>  To enable haptic feedback, you must declare the ohos.permission.VIBRATE permission under **requestPermissions** in the **module.json5** file of the project.
549> ```json
550> "requestPermissions": [
551>  {
552>     "name": "ohos.permission.VIBRATE",
553>  }
554> ]
555> ```
556
557## IconOptions<sup>10+</sup>
558
559**Atomic service API**: This API can be used in atomic services since API version 11.
560
561**System capability**: SystemCapability.ArkUI.ArkUI.Full
562
563| Name| Type                                  | Mandatory| Description   |
564| ------ | ------------------------------------------ | ---- | ----------- |
565| size   | [Length](ts-types.md#length)               | No  | Icon size. It cannot be set in percentage.   |
566| color  | [ResourceColor](ts-types.md#resourcecolor) | No  | Icon color.   |
567| src    | [ResourceStr](ts-types.md#resourcestr)     | No  | Image source of the icon.|
568
569## SearchButtonOptions<sup>10+</sup>
570
571**Atomic service API**: This API can be used in atomic services since API version 11.
572
573**System capability**: SystemCapability.ArkUI.ArkUI.Full
574
575| Name   | Type                                  | Mandatory| Description        |
576| --------- | ------------------------------------------ | ---- | ---------------- |
577| fontSize  | [Length](ts-types.md#length)               | No  | Font size of the button. It cannot be set in percentage.|
578| fontColor | [ResourceColor](ts-types.md#resourcecolor) | No  | Font color of the button.|
579
580## CancelButtonStyle<sup>10+</sup>
581
582**Atomic service API**: This API can be used in atomic services since API version 11.
583
584**System capability**: SystemCapability.ArkUI.ArkUI.Full
585
586| Name                   | Description            |
587| ----------------------- | ---------------- |
588| CONSTANT  | The Cancel button is always displayed.|
589| INVISIBLE | The Cancel button is always hidden.|
590| INPUT     | The Cancel button is displayed when there is text input.|
591
592## SearchType<sup>11+</sup>
593
594**Atomic service API**: This API can be used in atomic services since API version 12.
595
596**System capability**: SystemCapability.ArkUI.ArkUI.Full
597
598| Name                | Value           | Description           |
599| ------------------ | ------ | ------------- |
600| NORMAL   | 0 | Normal input mode.<br>The value can contain digits, letters, underscores (_), spaces, and special characters.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
601| NUMBER   | 2 | Digit input mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.     |
602| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
603| 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)<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
604| NUMBER_DECIMAL<sup>12+</sup>  | 12 | Number input mode with a decimal point.<br>The value can contain digits and one decimal point.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
605| URL<sup>12+</sup>  | 13 | URL input mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
606
607## CancelButtonOptions<sup>12+</sup>
608
609**Atomic service API**: This API can be used in atomic services since API version 12.
610
611**System capability**: SystemCapability.ArkUI.ArkUI.Full
612
613| Name   | Type                                  | Mandatory| Description        |
614| --------- | ------------------------------------------ | ---- | ---------------- |
615| style  | [CancelButtonStyle](#cancelbuttonstyle10)               | No  | Display state of the Cancel button on the right.|
616| icon | [IconOptions](#iconoptions10) | No  | Icon of the Cancel button on the right.|
617
618## CancelButtonSymbolOptions<sup>12+</sup>
619
620**Atomic service API**: This API can be used in atomic services since API version 12.
621
622**System capability**: SystemCapability.ArkUI.ArkUI.Full
623
624| Name   | Type                                  | Mandatory| Description        |
625| --------- | ------------------------------------------ | ---- | ---------------- |
626| style  | [CancelButtonStyle](#cancelbuttonstyle10)               | No  | Display state of the Cancel button on the right.|
627| icon | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | No  | Symbol icon of the Cancel button on the right.|
628
629## Events
630
631In addition to the [universal events](ts-universal-events-click.md), the following events are supported.
632
633### onSubmit
634
635onSubmit(callback: (value: string) => void)
636
637Invoked when users click the search icon or the search button, or touch the search button on a soft keyboard.
638
639**Atomic service API**: This API can be used in atomic services since API version 11.
640
641**System capability**: SystemCapability.ArkUI.ArkUI.Full
642
643**Parameters**
644
645| Name| Type  | Mandatory| Description                        |
646| ------ | ------ | ---- | ---------------------------- |
647| value  | string | Yes  | Current text input.|
648
649### onSubmit<sup>14+</sup>
650
651onSubmit(callback: SearchSubmitCallback)
652
653Invoked when the search icon, search button, or soft keyboard search button is clicked. The submission event provides a method to maintain the edit state of the **Search** component.
654
655**Atomic service API**: This API can be used in atomic services since API version 14.
656
657**System capability**: SystemCapability.ArkUI.ArkUI.Full
658
659**Parameters**
660
661| Name| Type   | Mandatory| Description                         |
662| ------ | ------- | ---- | ----------------------------- |
663| callback | [SearchSubmitCallback](#searchsubmitcallback14) | Yes  | Callback triggered when the search icon, search button, or soft keyboard search button is clicked.|
664
665### onChange
666
667onChange(callback: EditableTextOnChangeCallback)
668
669Invoked when the input in the text box changes.
670
671In this callback, if cursor operations are performed, you must adjust the cursor logic based on the **previewText** parameter to ensure it works seamlessly within the preview display scenario.
672
673**Atomic service API**: This API can be used in atomic services since API version 11.
674
675**System capability**: SystemCapability.ArkUI.ArkUI.Full
676
677**Parameters**
678
679| Name| Type  | Mandatory| Description                        |
680| ------ | ------ | ---- | ---------------------------- |
681| callback  | [EditableTextOnChangeCallback](ts-text-common.md#editabletextonchangecallback12) | Yes  | Callback invoked when the input in the text box changes.|
682
683### onCopy
684
685onCopy(callback: (value: string) => void)
686
687Invoked when a copy operation is performed.
688
689**Atomic service API**: This API can be used in atomic services since API version 11.
690
691**System capability**: SystemCapability.ArkUI.ArkUI.Full
692
693**Parameters**
694
695| Name| Type  | Mandatory| Description            |
696| ------ | ------ | ---- | ---------------- |
697| value  | string | Yes  | Text that is copied.|
698
699### onCut
700
701onCut(callback: (value: string) => void)
702
703Invoked when a cut operation is performed.
704
705**Atomic service API**: This API can be used in atomic services since API version 11.
706
707**System capability**: SystemCapability.ArkUI.ArkUI.Full
708
709**Parameters**
710
711| Name| Type  | Mandatory| Description            |
712| ------ | ------ | ---- | ---------------- |
713| value  | string | Yes  | Text that is cut.|
714
715### onPaste
716
717onPaste(callback: (value: string, event: PasteEvent) => void)
718
719Invoked when a paste operation is performed.
720
721**Atomic service API**: This API can be used in atomic services since API version 11.
722
723**System capability**: SystemCapability.ArkUI.ArkUI.Full
724
725**Parameters**
726
727| Name             | Type                                                        | Mandatory| Description                  |
728| ------------------- | ------------------------------------------------------------ | ---- | ---------------------- |
729| value               | string                                                       | Yes  | Text to be pasted.      |
730| event<sup>11+</sup> | [PasteEvent](ts-basic-components-richeditor.md#pasteevent11) | Yes  | Custom paste event.|
731
732### onTextSelectionChange<sup>10+</sup>
733
734onTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void)
735
736Invoked when the position of the text selection changes or when the cursor position changes during the editing state.
737
738**Atomic service API**: This API can be used in atomic services since API version 11.
739
740**System capability**: SystemCapability.ArkUI.ArkUI.Full
741
742**Parameters**
743
744| Name        | Type  | Mandatory| Description                                             |
745| -------------- | ------ | ---- | ------------------------------------------------- |
746| selectionStart | number | Yes  | Start position of the text selection range. The start position of text in the text box is 0.|
747| selectionEnd   | number | Yes  | End position of the text selection range.                           |
748
749### onContentScroll<sup>10+</sup>
750
751onContentScroll(callback: (totalOffsetX: number, totalOffsetY: number) => void)
752
753Invoked when the text content is scrolled.
754
755**Atomic service API**: This API can be used in atomic services since API version 11.
756
757**System capability**: SystemCapability.ArkUI.ArkUI.Full
758
759**Parameters**
760
761| Name      | Type  | Mandatory| Description                              |
762| ------------ | ------ | ---- | ---------------------------------- |
763| totalOffsetX | number | Yes  | Offset in the X coordinate of the text in the content area, in px.|
764| totalOffsetY | number | Yes  | Offset in the Y coordinate of the text in the content area, in px.|
765
766### onEditChange<sup>12+</sup>
767
768onEditChange(callback: Callback< boolean >)
769
770Invoked 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.
771
772**Atomic service API**: This API can be used in atomic services since API version 12.
773
774**System capability**: SystemCapability.ArkUI.ArkUI.Full
775
776**Parameters**
777
778| Name   | Type                               | Mandatory| Description                |
779| --------- | ---------------------------------- | ---- | -------------------- |
780| isEditing |  Callback< boolean > | Yes  | Whether the text box is in the editing state. The value **true** indicates that the text box is in the editing state.|
781
782### onWillInsert<sup>12+</sup>
783
784onWillInsert(callback: Callback\<InsertValue, boolean>)
785
786Invoked when text is about to be inserted.
787
788**Atomic service API**: This API can be used in atomic services since API version 12.
789
790**System capability**: SystemCapability.ArkUI.ArkUI.Full
791
792**Parameters**
793
794| Name| Type                                                        | Mandatory| Description              |
795| ------ | ------------------------------------------------------------ | ---- | ------------------ |
796| callback  | Callback\<[InsertValue](ts-text-common.md#insertvalue12), boolean> | Yes  | Callback invoked when text is about to be inserted.<br>It returns **true** if the text is inserted; returns **false** otherwise.<br>This callback is not invoked for text preview.<br>It is available only for system input methods.|
797
798### onDidInsert<sup>12+</sup>
799
800onDidInsert(callback: Callback\<InsertValue>)
801
802Invoked when text is inserted.
803
804**Atomic service API**: This API can be used in atomic services since API version 12.
805
806**System capability**: SystemCapability.ArkUI.ArkUI.Full
807
808**Parameters**
809
810| Name| Type                                                        | Mandatory| Description              |
811| ------ | ------------------------------------------------------------ | ---- | ------------------ |
812| callback  | Callback\<[InsertValue](ts-text-common.md#insertvalue12)> | Yes  | Callback invoked when text is inserted.<br>It is available only for system input methods.|
813
814### onWillDelete<sup>12+</sup>
815
816onWillDelete(callback: Callback\<DeleteValue, boolean>)
817
818Invoked when text is about to be deleted.
819
820**Atomic service API**: This API can be used in atomic services since API version 12.
821
822**System capability**: SystemCapability.ArkUI.ArkUI.Full
823
824**Parameters**
825
826| Name| Type                                                        | Mandatory| Description              |
827| ------ | ------------------------------------------------------------ | ---- | ------------------ |
828| callback  | Callback\<[DeleteValue](ts-text-common.md#deletevalue12), boolean> | Yes  | Callback invoked when text is about to be deleted.<br>It returns **true** if the text is deleted; returns **false** otherwise.<br>This callback is not invoked for text preview.<br>It is available only for system input methods.|
829
830### onDidDelete<sup>12+</sup>
831
832onDidDelete(callback: Callback\<DeleteValue>)
833
834Called when text is deleted.
835
836**Atomic service API**: This API can be used in atomic services since API version 12.
837
838**System capability**: SystemCapability.ArkUI.ArkUI.Full
839
840**Parameters**
841
842| Name| Type                                                        | Mandatory| Description              |
843| ------ | ------------------------------------------------------------ | ---- | ------------------ |
844| callback  | Callback\<[DeleteValue](ts-text-common.md#deletevalue12)> | Yes  | Callback invoked when text is deleted.<br>It is available only for system input methods.|
845
846## SearchController
847
848Inherits from [TextContentControllerBase](ts-types.md#textcontentcontrollerbase10).
849
850### Objects to Import
851```
852controller: SearchController = new SearchController()
853```
854
855### constructor<sup>8+</sup>
856
857constructor()
858
859A constructor used to create a **SearchController** object.
860
861**Atomic service API**: This API can be used in atomic services since API version 11.
862
863**System capability**: SystemCapability.ArkUI.ArkUI.Full
864
865### caretPosition<sup>8+</sup>
866
867caretPosition(value: number): void
868
869Sets the position of the caret.
870
871**Atomic service API**: This API can be used in atomic services since API version 11.
872
873**System capability**: SystemCapability.ArkUI.ArkUI.Full
874
875**Parameters**
876
877| Name| Type| Mandatory| Description                          |
878| ------ | -------- | ---- | ---------------------------------- |
879| value  | number   | Yes  | Length from the start of the character string to the position where the caret is located.|
880
881### stopEditing<sup>10+</sup>
882
883stopEditing(): void
884
885Exits the editing state.
886
887**Atomic service API**: This API can be used in atomic services since API version 11.
888
889**System capability**: SystemCapability.ArkUI.ArkUI.Full
890
891### setTextSelection<sup>12+</sup>
892
893setTextSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void;
894
895Sets 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**.
896
897**Atomic service API**: This API can be used in atomic services since API version 12.
898
899**System capability**: SystemCapability.ArkUI.ArkUI.Full
900
901**Parameters**
902
903| Name        | Type| Mandatory| Description  |
904| -------------- | -------- | ---- | -------- |
905| 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>|
906| 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>|
907| options | [SelectionOptions](ts-types.md#selectionoptions12) | No   | Configuration options for text selection.<br>Default value: **MenuPolicy.DEFAULT**|
908
909>  **NOTE**
910>
911>  If **selectionStart** or **selectionEnd** is set to **undefined**, the value **0** will be used.
912>
913>  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**.
914>
915>  If the selected text contains an emoji, the emoji is selected when its start position is within the text selection range.
916
917## SearchSubmitCallback<sup>14+</sup>
918
919type SearchSubmitCallback = (searchContent: string, event?: SubmitEvent) => void
920
921Represents the callback triggered when the search icon, search button, or soft keyboard search button is clicked.
922
923**Atomic service API**: This API can be used in atomic services since API version 14.
924
925**System capability**: SystemCapability.ArkUI.ArkUI.Full
926
927**Parameters**
928
929| Name  | Type                                                        | Mandatory| Description                                                    |
930| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
931| searchContent | string             | Yes  | Current text input.|
932| event    | [SubmitEvent](ts-basic-components-textinput.md#submitevent11) | No  | Submit event.   |
933
934##  Example
935
936### Example 1: Setting and Obtaining the Cursor Position
937
938This example demonstrates how to use the controller to set and obtain the cursor position within a text box.
939
940```ts
941// xxx.ets
942@Entry
943@Component
944struct SearchExample {
945  @State changeValue: string = ''
946  @State submitValue: string = ''
947  @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
948  controller: SearchController = new SearchController()
949
950  build() {
951    Column({space: 10}) {
952      Text('onSubmit:' + this.submitValue).fontSize(18).margin(15)
953      Text('onChange:' + this.changeValue).fontSize(18).margin(15)
954      Search({ value: this.changeValue, placeholder: 'Type to search...', controller: this.controller })
955        .searchButton('SEARCH')
956        .width('95%')
957        .height(40)
958        .backgroundColor('#F5F5F5')
959        .placeholderColor(Color.Grey)
960        .placeholderFont({ size: 14, weight: 400 })
961        .textFont({ size: 14, weight: 400 })
962        .onSubmit((value: string) => {
963          this.submitValue = value
964        })
965        .onChange((value: string) => {
966          this.changeValue = value
967        })
968        .margin(20)
969      Button('Set caretPosition 1')
970        .onClick(() => {
971          // Move the caret to after the first entered character.
972          this.controller.caretPosition(1)
973        })
974      Button('Get CaretOffset')
975        .onClick(() => {
976          this.positionInfo = this.controller.getCaretOffset()
977        })
978    }.width('100%')
979  }
980}
981```
982
983![search](figures/search.gif)
984
985### Example 2: Setting Search and Delete Icons
986
987This example demonstrates how to set search and delete icons using the **searchButton**, **searchIcon**, and **cancelButton** attributes.
988
989```ts
990// xxx.ets
991@Entry
992@Component
993struct SearchExample {
994  @State changeValue: string = ''
995  @State submitValue: string = ''
996
997  build() {
998    Column() {
999      Text('onSubmit:' + this.submitValue).fontSize(18).margin(15)
1000      Search({ value: this.changeValue, placeholder: 'Type to search...' })
1001        .searchButton('SEARCH')
1002        .searchIcon({
1003          src: $r('app.media.search')
1004        })
1005        .cancelButton({
1006          style: CancelButtonStyle.CONSTANT,
1007          icon: {
1008            src: $r('app.media.cancel')
1009          }
1010        })
1011        .width('90%')
1012        .height(40)
1013        .maxLength(20)
1014        .backgroundColor('#F5F5F5')
1015        .placeholderColor(Color.Grey)
1016        .placeholderFont({ size: 14, weight: 400 })
1017        .textFont({ size: 14, weight: 400 })
1018        .onSubmit((value: string) => {
1019          this.submitValue = value
1020        })
1021        .onChange((value: string) => {
1022          this.changeValue = value
1023        })
1024        .margin(20)
1025    }.width('100%')
1026  }
1027}
1028```
1029
1030![searchButton](figures/searchButton.gif)
1031
1032
1033### Example 3: Implementing a Custom Keyboard
1034
1035This example demonstrates how to implement a custom keyboard using the **customKeyboard** attribute.
1036
1037```ts
1038// xxx.ets
1039@Entry
1040@Component
1041struct SearchExample {
1042  controller: SearchController = new SearchController()
1043  @State inputValue: string = ""
1044
1045  // Create a custom keyboard component.
1046  @Builder CustomKeyboardBuilder() {
1047    Column() {
1048      Button('x').onClick(() => {
1049        // Disable the custom keyboard.
1050        this.controller.stopEditing()
1051      })
1052      Grid() {
1053        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => {
1054          GridItem() {
1055            Button(item + "")
1056              .width(110).onClick(() => {
1057              this.inputValue += item
1058            })
1059          }
1060        })
1061      }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
1062    }.backgroundColor(Color.Gray)
1063  }
1064
1065  build() {
1066    Column() {
1067      Search({ controller: this.controller, value: this.inputValue})
1068        // Bind the custom keyboard.
1069        .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 })
1070    }
1071  }
1072}
1073```
1074
1075![customKeyboard](figures/searchCustomKeyboard.png)
1076
1077### Example 4: Setting the Enter Key Type
1078
1079This example shows how to use the **enterKeyType** attribute to dynamically change the effect of the Enter key on the soft keyboard.
1080
1081```ts
1082// xxx.ets
1083@Entry
1084@Component
1085struct SearchExample {
1086  @State text: string = ''
1087  @State enterTypes: Array<EnterKeyType> = [EnterKeyType.Go, EnterKeyType.Search, EnterKeyType.Send, EnterKeyType.Done, EnterKeyType.Next, EnterKeyType.PREVIOUS, EnterKeyType.NEW_LINE]
1088  @State index: number = 0
1089  build() {
1090    Column({ space: 20 }) {
1091      Search({ placeholder: 'Enter text', value: this.text })
1092        .width(380)
1093        .enterKeyType(this.enterTypes[this.index])
1094        .onChange((value: string) => {
1095          this.text = value
1096        })
1097        .onSubmit((value: String) => {
1098          console.log("trigger search onsubmit" + value);
1099        })
1100
1101      Button('Change EnterKeyType').onClick(() => {
1102        this.index = (this.index + 1) % this.enterTypes.length;
1103      })
1104    }.width('100%')
1105  }
1106}
1107```
1108
1109![searchEnterKeyType](figures/searchEnterKey.gif)
1110
1111### Example 5: Setting the Text Style
1112
1113This example showcases various text styles by using the **lineHeight**, **letterSpacing**, and **decoration** attributes.
1114
1115```ts
1116// xxx.ets
1117@Entry
1118@Component
1119struct SearchExample {
1120  build() {
1121    Row() {
1122      Column() {
1123        Text('lineHeight').fontSize(9).fontColor(0xCCCCCC)
1124        Search({value: 'lineHeight unset'})
1125          .border({ width: 1 }).padding(10)
1126        Search({value: 'lineHeight 15'})
1127          .border({ width: 1 }).padding(10).lineHeight(15)
1128        Search({value: 'lineHeight 30'})
1129          .border({ width: 1 }).padding(10).lineHeight(30)
1130
1131        Text('letterSpacing').fontSize(9).fontColor(0xCCCCCC)
1132        Search({value: 'letterSpacing 0'})
1133          .border({ width: 1 }).padding(5).letterSpacing(0)
1134        Search({value: 'letterSpacing 3'})
1135          .border({ width: 1 }).padding(5).letterSpacing(3)
1136        Search({value: 'letterSpacing -1'})
1137          .border({ width: 1 }).padding(5).letterSpacing(-1)
1138
1139        Text('decoration').fontSize(9).fontColor(0xCCCCCC)
1140        Search({value: 'LineThrough, Red'})
1141          .border({ width: 1 }).padding(5)
1142          .decoration({type: TextDecorationType.LineThrough, color: Color.Red})
1143        Search({value: 'Overline, Red, DOTTED'})
1144          .border({ width: 1 }).padding(5)
1145          .decoration({type: TextDecorationType.Overline, color: Color.Red, style: TextDecorationStyle.DOTTED})
1146        Search({value: 'Underline, Red, WAVY'})
1147          .border({ width: 1 }).padding(5)
1148          .decoration({type: TextDecorationType.Underline, color: Color.Red, style: TextDecorationStyle.WAVY})
1149      }.height('90%')
1150    }
1151    .width('90%')
1152    .margin(10)
1153  }
1154}
1155
1156```
1157
1158![SearchDecoration](figures/search_decoration.png)
1159
1160### Example 6: Setting Text Feature Effects
1161
1162This example demonstrates how to use the **fontFeature** attribute to display text with various typographic features.
1163
1164```ts
1165// xxx.ets
1166@Entry
1167@Component
1168struct SearchExample {
1169  @State text1: string = 'This is ss01 on : 0123456789'
1170  @State text2: string = 'This is ss01 off: 0123456789'
1171
1172  build() {
1173    Column(){
1174      Search({value: this.text1})
1175        .margin({top:200})
1176        .fontFeature("\"ss01\" on")
1177      Search({value: this.text2})
1178        .margin({top:10})
1179        .fontFeature("\"ss01\" off")
1180    }
1181    .width("90%")
1182    .margin("5%")
1183  }
1184}
1185```
1186![fontFeature](figures/searchFontFeature.png)
1187
1188### Example 7: Setting Custom Keyboard Avoidance
1189
1190This example illustrates the implementation of a custom keyboard that automatically adjusts its position to avoid covering the text box.
1191
1192```ts
1193// xxx.ets
1194@Entry
1195@Component
1196struct SearchExample {
1197  controller: SearchController = new SearchController()
1198  @State inputValue: string = ""
1199  @State height1: string | number = '80%'
1200  @State supportAvoidance: boolean = true
1201
1202  // Create a custom keyboard component.
1203  @Builder
1204  CustomKeyboardBuilder() {
1205    Column() {
1206      Row() {
1207        Button('x').onClick(() => {
1208          // Disable the custom keyboard.
1209          this.controller.stopEditing()
1210        }).margin(10)
1211      }
1212
1213      Grid() {
1214        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => {
1215          GridItem() {
1216            Button(item + "")
1217              .width(110).onClick(() => {
1218              this.inputValue += item
1219            })
1220          }
1221        })
1222      }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
1223    }
1224    .backgroundColor(Color.Gray)
1225  }
1226
1227  build() {
1228    Column() {
1229      Row() {
1230        Button("20%")
1231          .fontSize(24)
1232          .onClick(() => {
1233            this.height1 = "20%"
1234          })
1235        Button("80%")
1236          .fontSize(24)
1237          .margin({ left: 20 })
1238          .onClick(() => {
1239            this.height1 = "80%"
1240          })
1241      }
1242      .justifyContent(FlexAlign.Center)
1243      .alignItems(VerticalAlign.Bottom)
1244      .height(this.height1)
1245      .width("100%")
1246      .padding({ bottom: 50 })
1247
1248      Search({ controller: this.controller, value: this.inputValue })// Bind a custom keyboard.
1249        .customKeyboard(this.CustomKeyboardBuilder(), { supportAvoidance: this.supportAvoidance })
1250        .margin(10)
1251        .border({ width: 1 })
1252        .onChange((value: string) => {
1253          this.inputValue = value
1254        })
1255    }
1256  }
1257}
1258```
1259
1260![CustomSearchKeyType](figures/searchCustomKeyboard.gif)
1261
1262### Example 8: Setting Text Auto-Adaptation
1263
1264This example showcases the implementation of text auto-adaptation features using the **minFontSize** and **maxFontSize** attributes.
1265
1266```ts
1267// xxx.ets
1268@Entry
1269@Component
1270struct SearchExample {
1271  build() {
1272    Row() {
1273      Column() {
1274        Text('adaptive font').fontSize(9).fontColor(0xCCCCCC)
1275
1276        Search({value: 'This is the text without the adaptive font'})
1277          .width('80%').height(90).borderWidth(1)
1278        Search({value: 'This is the text without the adaptive font'})
1279          .width('80%').height(90).borderWidth(1)
1280          .minFontSize(4)
1281          .maxFontSize(40)
1282      }.height('90%')
1283    }
1284    .width('90%')
1285    .margin(10)
1286  }
1287}
1288```
1289
1290![searchAdaptFont](figures/search_adapt_font.png)
1291
1292### Example 9: Setting Insert and Delete Callbacks
1293
1294This example showcases the implementation of insert and delete operations using the **onWillInsert**, **onDidInsert**, **onWillDelete**, and **onDidDelete** APIs.
1295
1296```ts
1297// xxx.ets
1298@Entry
1299@Component
1300struct SearchExample {
1301  @State insertValue: string = ""
1302  @State deleteValue: string = ""
1303  @State insertOffset: number = 0
1304  @State deleteOffset: number = 0
1305  @State deleteDirection: number = 0
1306
1307  build() {
1308    Row() {
1309      Column() {
1310        Search({ value: "Insert callbacks are supported" })
1311          .height(60)
1312          .onWillInsert((info: InsertValue) => {
1313            this.insertValue = info.insertValue
1314            return true;
1315          })
1316          .onDidInsert((info: InsertValue) => {
1317            this.insertOffset = info.insertOffset
1318          })
1319
1320        Text("insertValue:" + this.insertValue + "  insertOffset:" + this.insertOffset).height(30)
1321
1322        Search({ value: "Delete callbacks are supported" })
1323          .height(60)
1324          .onWillDelete((info: DeleteValue) => {
1325            this.deleteValue = info.deleteValue
1326            info.direction
1327            return true;
1328          })
1329          .onDidDelete((info: DeleteValue) => {
1330            this.deleteOffset = info.deleteOffset
1331            this.deleteDirection = info.direction
1332          })
1333
1334        Text("deleteValue:" + this.deleteValue + "  deleteOffset:" + this.deleteOffset).height(30)
1335        Text("deleteDirection:" + (this.deleteDirection == 0 ? "BACKWARD" : "FORWARD")).height(30)
1336
1337      }.width('100%')
1338    }
1339    .height('100%')
1340  }
1341}
1342```
1343
1344![SearchInsertAndDelete](figures/SearchInsertAndDelete.PNG)
1345
1346### Example 10: Setting Custom Menu Extensions
1347
1348This 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.
1349
1350```ts
1351// xxx.ets
1352@Entry
1353@Component
1354struct SearchExample {
1355  @State text: string = 'Search editMenuOptions'
1356  onCreateMenu = (menuItems: Array<TextMenuItem>) => {
1357    let item1: TextMenuItem = {
1358      content: 'custom1',
1359      icon: $r('app.media.startIcon'),
1360      id: TextMenuItemId.of('custom1'),
1361    }
1362    let item2: TextMenuItem = {
1363      content: 'custom2',
1364      id: TextMenuItemId.of('custom2'),
1365      icon: $r('app.media.startIcon'),
1366    }
1367    menuItems.push(item1)
1368    menuItems.unshift(item2)
1369    return menuItems
1370  }
1371  onMenuItemClick = (menuItem: TextMenuItem, textRange: TextRange) => {
1372    if (menuItem.id.equals(TextMenuItemId.of("custom2"))) {
1373      console.log("Intercept id: custom2 start:" + textRange.start + "; end:" + textRange.end)
1374      return true
1375    }
1376    if (menuItem.id.equals(TextMenuItemId.COPY)) {
1377      console.log("Intercept COPY start:" + textRange.start + "; end:" + textRange.end)
1378      return true
1379    }
1380    if (menuItem.id.equals(TextMenuItemId.SELECT_ALL)) {
1381      console.log("Do not intercept SELECT_ALL start:" + textRange.start + "; end:" + textRange.end)
1382      return false
1383    }
1384    return false
1385  }
1386  @State editMenuOptions: EditMenuOptions = {
1387    onCreateMenu: this.onCreateMenu, onMenuItemClick: this.onMenuItemClick
1388  }
1389
1390  build() {
1391    Column() {
1392      Search({ value: this.text })
1393        .width('95%')
1394        .editMenuOptions(this.editMenuOptions)
1395        .margin({ top: 100 })
1396    }
1397    .width("90%")
1398    .margin("5%")
1399  }
1400}
1401```
1402
1403![searchEditMenuOptions](figures/searchEditMenuOptions.gif)
1404
1405### Example 11: Setting a Custom Symbol-Type Cancel Button
1406
1407This example demonstrates how to use the **searchIcon** and **cancelButton** attributes to customize the style of the symbol-type cancel button on the right side of the text box.
1408
1409```ts
1410// xxx.ets
1411import { SymbolGlyphModifier } from '@kit.ArkUI'
1412
1413@Entry
1414@Component
1415struct SearchExample {
1416  controller: SearchController = new SearchController()
1417  @State changeValue: string = ''
1418  @State submitValue: string = ''
1419
1420  build() {
1421    Column() {
1422      Search({ value: this.changeValue, placeholder: 'Type to search...', controller: this.controller })
1423        .searchIcon(new SymbolGlyphModifier($r('sys.symbol.magnifyingglass')).fontColor([Color.Red]))
1424        .cancelButton({
1425          style: CancelButtonStyle.CONSTANT,
1426          icon: new SymbolGlyphModifier($r('sys.symbol.xmark')).fontColor([Color.Green])
1427        })
1428        .searchButton('SEARCH')
1429        .width('95%')
1430        .height(40)
1431        .backgroundColor('#F5F5F5')
1432        .placeholderColor(Color.Grey)
1433        .placeholderFont({ size: 14, weight: 400 })
1434        .textFont({ size: 14, weight: 400 })
1435        .margin(10)
1436    }
1437    .width('100%')
1438    .height('100%')
1439  }
1440}
1441```
1442
1443![searchSymbolGlyphModifierIcon](figures/searchSymbolGlyphModifierIcon.png)
1444