js-components-basic-search.md 5.4 KB
Newer Older
E
ester.zhou 已提交
1
# search
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3 4
>  **NOTE**
>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
5

E
ester.zhou 已提交
6
The **\<search>** component provides an input area for users to search.
E
ester.zhou 已提交
7 8 9


## Child Components
Z
zengyawen 已提交
10 11 12 13

Not supported


E
ester.zhou 已提交
14
## Attributes
Z
zengyawen 已提交
15

E
ester.zhou 已提交
16
In addition to the [universal attributes](../arkui-js/js-components-common-attributes.md), the following attributes are supported.
Z
zengyawen 已提交
17

E
ester.zhou 已提交
18 19 20 21 22 23 24
| Name                       | Type                     | Default Value | Mandatory  | Description                               |
| ------------------------- | ----------------------- | ---- | ---- | --------------------------------- |
| icon                      | string                  | -    | No   | Search icon. By default, the system search icon is used. The supported icon format is SVG, JPG, and PNG.|
| hint                      | string                  | -    | No   | Hint text.                          |
| value                     | string                  | -    | No   | Text in the search box.                        |
| searchbutton<sup>5+</sup> | string                  | -    | No   | Text on the search button at the end of the search box.                    |
| menuoptions<sup>5+</sup>  | Array&lt;MenuOption&gt; | -    | No   | Menu options displayed after users click the **More** button.          |
Z
zengyawen 已提交
25

E
ester.zhou 已提交
26
**Table 1** MenuOption<sup>5+</sup>
Z
zengyawen 已提交
27

E
ester.zhou 已提交
28 29 30 31
| Name     | Type    | Description         |
| ------- | ------ | ----------- |
| icon    | string | Path of the icon for a menu option.|
| content | string | Text content of a menu option.|
Z
zengyawen 已提交
32 33


E
ester.zhou 已提交
34
## Styles
Z
zengyawen 已提交
35

E
ester.zhou 已提交
36
In addition to the [universal styles](../arkui-js/js-components-common-styles.md), the following styles are supported.
Z
zengyawen 已提交
37

E
ester.zhou 已提交
38 39 40 41 42 43
| Name                      | Type                        | Default Value            | Mandatory  | Description                                      |
| ------------------------ | -------------------------- | --------------- | ---- | ---------------------------------------- |
| color                    | &lt;color&gt;              | \#e6000000      | No   | Font color of the search box.                               |
| font-size                | &lt;length&gt;             | 16px            | No   | Font size of the search box.                               |
| allow-scale              | boolean                    | true            | No   | Whether the font size changes with the system's font size settings.<br>If the **config-changes** tag of **fontSize** is configured for abilities in the **config.json** file, the setting takes effect without application restart.|
| placeholder-color        | &lt;color&gt;              | \#99000000<br>| No   | Color of the hint text.                             |
E
ester.zhou 已提交
44
| font-weight              | number \| string | normal          | No   | Font weight. For details, see [font-weight](../arkui-js/js-components-basic-text.md#styles) of the **\<text>** component.|
E
ester.zhou 已提交
45 46
| font-family              | string                     | sans-serif      | No   | Font family, in which fonts are separated by commas (,). Each font is set using a font name or font family name. The first font in the family or the specified [custom font](../arkui-js/js-components-common-customizing-font.md) is used for the text.|
| caret-color<sup>6+</sup> | &lt;color&gt;              | -               | No   | Color of the caret.                              |
Z
zengyawen 已提交
47 48


E
ester.zhou 已提交
49
## Events
Z
zengyawen 已提交
50

E
ester.zhou 已提交
51
In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.
Z
zengyawen 已提交
52

E
ester.zhou 已提交
53 54 55 56 57 58 59 60
| Name                       | Parameter                                      | Description                                      |
| ------------------------- | ---------------------------------------- | ---------------------------------------- |
| change                    | { text:newText }               | Triggered when the content entered in the text box changes.<br>If you change the **value** attribute directly, this event will not be triggered.     |
| submit                    | { text:submitText }            | Triggered when users click the search icon or the search button<sup>5+</sup>, or tap the search button on a soft keyboard. |
| translate<sup>5+</sup>    | { value: selectedText }   | Triggered when users click the translate button in the menu displayed after they select a text segment. The selected text content is returned.|
| share<sup>5+</sup>        | { value: selectedText }   | Triggered when users click the share button in the menu displayed after they select a text segment. The selected text content is returned.|
| search<sup>5+</sup>       | { value: selectedText }   | Triggered when users click the search button in the menu displayed after they select a text segment. The selected text content is returned.|
| optionselect<sup>5+</sup> | { index:optionIndex, value: selectedText } | Triggered when users click a menu option in the menu displayed after they select a text segment. This event is valid only when the **menuoptions** attribute is set. The option index and selected text content are returned.|
Z
zengyawen 已提交
61

E
ester.zhou 已提交
62 63 64 65 66 67 68 69 70

## Methods

The [universal methods](../arkui-js/js-components-common-methods.md) are supported.


## Example

```html
Z
zengyawen 已提交
71 72
<!-- xxx.hml -->
<div class="container">
E
ester.zhou 已提交
73
    <search hint="Enter keywords" searchbutton="Search" @search="search">
Z
zengyawen 已提交
74 75 76 77
  </search>
</div>
```

E
ester.zhou 已提交
78
```css
Z
zengyawen 已提交
79 80 81 82 83 84 85 86
/* xxx.css */
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
```

E
ester.zhou 已提交
87
![en-us_image_0000001153427082](figures/en-us_image_0000001153427082.png)