1e41f4b71Sopenharmony_ci# menu 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe **\<menu>** component provides menus as temporary pop-up windows to display operations that can be performed by users. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Required Permissions 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciNone 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## Child Components 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciOnly the **[\<option>](js-components-basic-option.md)** component is supported. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## Attributes 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 24e41f4b71Sopenharmony_ci| ------ | ------ | ----- | ---- | ---------------------------------------- | 25e41f4b71Sopenharmony_ci| target | string | - | No | Target element to which the menu is attached. When the target element is clicked, the menu is automatically displayed. The menu is preferentially displayed in the lower right corner of the target element. If the visible space on the right is insufficient, the menu is moved leftward. If the visible space in the lower part is insufficient, the menu is moved upward.| 26e41f4b71Sopenharmony_ci| type | string | click | No | Mode in which the target element triggers the pop-up menu. Available values are as follows:<br>- **click**: The pop-up menu is triggered by clicking the target element.<br>- **longpress**: The pop-up menu is triggered by long pressing the target element.| 27e41f4b71Sopenharmony_ci| title | string | - | No | Title of the menu. | 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci> **NOTE** 30e41f4b71Sopenharmony_ci> 31e41f4b71Sopenharmony_ci> The **focusable** and **disabled** attributes are not supported. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## Styles 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ciThe following styles are supported. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 39e41f4b71Sopenharmony_ci| -------------- | -------------------------- | ---------- | ---- | ---------------------------------------- | 40e41f4b71Sopenharmony_ci| text-color | <color> | - | No | Font color of the menu. | 41e41f4b71Sopenharmony_ci| font-size | <length> | 30px | No | Font size of the menu. | 42e41f4b71Sopenharmony_ci| 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.| 43e41f4b71Sopenharmony_ci| letter-spacing | <length> | 0 | No | Character spacing of the menu. | 44e41f4b71Sopenharmony_ci| font-style | string | normal | No | Font style of the menu. For details, see **font-weight** of the [**\<text>**](js-components-basic-text.md#styles) component.| 45e41f4b71Sopenharmony_ci| font-weight | number \| string | normal | No | Font weight of the menu. For details, see **font-weight** of the [**\<text>**](js-components-basic-text.md#styles) component.| 46e41f4b71Sopenharmony_ci| 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](js-components-common-customizing-font.md) is used for the text.| 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci## Events 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciThe following events are supported. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci| Name | Parameter | Description | 54e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---------------------------------------- | 55e41f4b71Sopenharmony_ci| selected | { value:value } | Triggered when a value in the menu is selected. The return value is the **value** attribute of the **\<option>** component.| 56e41f4b71Sopenharmony_ci| cancel | - | Triggered when an operation is canceled by the user. | 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci## Methods 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciThe following methods are supported. 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| Name | Parameter | Description | 64e41f4b71Sopenharmony_ci| ---- | --------------------------------- | ---------------------------------------- | 65e41f4b71Sopenharmony_ci| show | { x:x, y:y } | Displays the menu. **x** and **y** specify the position of the displayed menu. **x** indicates the x coordinate from the left edge of the visible area, and does not include any scrolling offset. **y** indicates the y 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 of the target element. If the visible space on the right is insufficient, the menu is moved leftward. If the visible space in the lower part is insufficient, the menu is moved upward.| 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci## Example 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci```html 70e41f4b71Sopenharmony_ci<!-- xxx.hml --> 71e41f4b71Sopenharmony_ci<div class="container"> 72e41f4b71Sopenharmony_ci <text onclick="onTextClick" class="title-text">Show popup menu.</text> 73e41f4b71Sopenharmony_ci <menu id="apiMenu" onselected="onMenuSelected"> 74e41f4b71Sopenharmony_ci <option value="Item 1">Item 1</option> 75e41f4b71Sopenharmony_ci <option value="Item 2">Item 2</option> 76e41f4b71Sopenharmony_ci <option value="Item 3">Item 3</option> 77e41f4b71Sopenharmony_ci </menu> 78e41f4b71Sopenharmony_ci</div> 79e41f4b71Sopenharmony_ci``` 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci```css 82e41f4b71Sopenharmony_ci/* xxx.css */ 83e41f4b71Sopenharmony_ci.container { 84e41f4b71Sopenharmony_ci flex-direction: column; 85e41f4b71Sopenharmony_ci align-items: flex-start; 86e41f4b71Sopenharmony_ci justify-content: center; 87e41f4b71Sopenharmony_ci} 88e41f4b71Sopenharmony_ci.title-text { 89e41f4b71Sopenharmony_ci margin: 20px; 90e41f4b71Sopenharmony_ci} 91e41f4b71Sopenharmony_ci``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci```js 94e41f4b71Sopenharmony_ci// xxx.js 95e41f4b71Sopenharmony_ciimport promptAction from '@ohos.promptAction'; 96e41f4b71Sopenharmony_ciexport default { 97e41f4b71Sopenharmony_ci onMenuSelected(e) { 98e41f4b71Sopenharmony_ci promptAction.showToast({ 99e41f4b71Sopenharmony_ci message: e.value 100e41f4b71Sopenharmony_ci }) 101e41f4b71Sopenharmony_ci }, 102e41f4b71Sopenharmony_ci onTextClick() { 103e41f4b71Sopenharmony_ci this.$element("apiMenu").show({x:280,y:120}); 104e41f4b71Sopenharmony_ci } 105e41f4b71Sopenharmony_ci} 106e41f4b71Sopenharmony_ci``` 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci 109