1# menu 2 3The **\<menu>** component provides menus as temporary pop-up windows to display operations that can be performed by users. 4 5## Required Permissions 6 7None 8 9## Child Components 10 11**[option](js-components-basic-option.md)** 12 13## Attributes 14 15In addition to the attributes in [Universal Attributes](js-components-common-attributes.md), the following attributes are supported. 16 17 18 19| Name | Type | Default Value | Mandatory | Description | 20| ------ | ------ | ------------- | --------- | ------------------------------------------------------------ | 21| target | string | - | No | Target element selector. After the target element selector is used, a menu is automatically displayed when you click the target element. The pop-up menu is preferentially displayed in the lower right corner of the target element. When the visible space on the right is insufficient, the menu is moved leftward. When the visible space in the lower part is insufficient, the menu is moved upward. | 22| type | string | click | No | Mode in which the target element triggers the pop-up window. Available values are as follows:<br/>-**click**: Click the element to trigger the pop-up window.<br/>-**longpress**: Press and hold the element to trigger the pop-up window. | 23| title | string | - | No | Title of the pop-up window. | 24 25>  **NOTE:** The **focusable** and **disabled** attributes are not supported. 26 27## Styles 28 29Only the following style attributes are supported. 30 31 32 33| Name | Type | Default Value | Mandatory | Description | 34| -------------- | ---------------- | ------------- | --------- | ------------------------------------------------------------ | 35| text-color | \<color> | - | No | Font color of the menu. | 36| font-size | \<length> | 30px | No | Font size of the menu. | 37| allow-scale | boolean | true | No | Whether the font size changes with the system's font size settings.NOTE:If the **config-changes** tag of **fontSize** is configured for abilities in the **config.json** file, the setting takes effect without application restart. | 38| letter-spacing | \<length> | 0 | No | Character spacing of the menu. | 39| font-style | string | normal | No | Font style of the menu. For details, see [font-style](js-components-basic-text.md#section5775351116) of the **text** component. | 40| font-weight | number \| string | normal | No | Font weight of the menu. For details, see [font-weight](js-components-basic-text.md#section5775351116) of the **text** component. | 41| 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 that exists in the system or the font specified by [Custom Font Styles](js-components-common-customizing-font.md) in the family is selected as the font for the text. | 42 43## Events 44 45The following events are supported. 46 47 48 49| Name | Parameter | Description | 50| -------- | --------------- | ------------------------------------------------------------ | 51| selected | { value:value } | Triggered when a value in the menu is selected. The returned value is the **value** attribute of the **\<option>** component. | 52| cancel | - | Triggered when an operation is canceled by the user | 53 54## Methods 55 56The following methods are supported. 57 58 59 60| Name | Parameter | Description | 61| ---- | ------------ | ------------------------------------------------------------ | 62| show | { x:x, y:y } | Displays the menu. *x* and *y* specify the position of the displayed menu. *x* indicates the X-axis coordinate from the left edge of the visible area, and does not include any scrolling offset. *y* indicates the Y-axis coordinate from the upper edge of the visible area, and does not include any scrolling offset or a status bar. The menu is preferentially displayed in the lower right corner. When the visible space on the right is insufficient, the menu is moved leftward. When the visible space in the lower part is insufficient, the menu is moved upward. | 63 64## Example 65 66``` 67<!-- xxx.hml --> 68<div class="container"> 69 <text onclick="onTextClick" class="title-text">Show popup menu.</text> 70 <menu id="apiMenu" onselected="onMenuSelected"> 71 <option value="Item 1">Item 1</option> 72 <option value="Item 2">Item 2</option> 73 <option value="Item 3">Item 3</option> 74 </menu> 75</div> 76/* xxx.css */ 77.container { 78 flex-direction: column; 79 align-items: flex-start; 80 justify-content: center; 81} 82.title-text { 83 margin: 20px; 84} 85// xxx.js 86import prompt from '@system.prompt'; 87export default { 88 onMenuSelected(e) { 89 prompt.showToast({ 90 message: e.value 91 }) 92 }, 93 onTextClick() { 94 this.$element("apiMenu").show({x:280,y:120}); 95 } 96} 97``` 98 99