Menu Overview
A menu is a pop-up window that allows users to perform specific actions. It typically appears when users right-click, long-press, or touch an item.
When to Use
| API | Use Case |
|---|---|
| Menu control (Menu) | Used to bind actions to specified components, such as displaying operation options when an icon is long-pressed. |
| Global menu independent of UI components (openMenu) | Used to provide operation options in scenarios where UI components cannot be directly accessed, for example, in event callbacks. |
Constraints
- When bindMenu is triggered via the isShow parameter or bindContextMenu is triggered via the isShown parameter, the menu requires complete page construction before display. Therefore, avoid setting isShow or isShown to true during the page build phase, as this may cause incorrect menu positioning and rendering.
- When using openMenu, you must provide valid TargetInfo. Otherwise, the menu won't display correctly.
- For details about other specifications, see Menu Control and openMenu.
Lifecycle
The normal sequence is aboutToAppear > onWillAppear > onAppear > onDidAppear > aboutToDisappear > onWillDisappear > onDisappear > onDidDisappear.
| Name | Type | Description |
|---|---|---|
| aboutToAppear | () => void | Callback invoked when the menu is about to appear. |
| onAppear | () => void | Callback invoked after the menu appears. |
| aboutToDisappear | () => void | Callback invoked when the menu is about to disappear. |
| onDisappear | () => void | Callback invoked after the menu disappears. |
| onWillAppear | Callback<void> | Callback invoked before the menu appearance animation. Note: aboutToAppear is invoked during initialization; onWillAppear is invoked before the animation starts; onWillAppear is invoked after aboutToAppear. |
| onDidAppear | Callback<void> | Callback invoked after the menu appears. NOTE 1. If you quickly tap the button, the menu will be quickly displayed and then disappear. In this case, onWillDisappear may take effect before onDidAppear. 2. If the menu is closed before the menu entrance animation is complete, this callback is not triggered. 3. onAppear and onDidAppear are invoked at the same time. onDidAppear takes effect after onAppear. |
| onWillDisappear | Callback<void> | Callback invoked before the menu disappearance animation. NOTE 1. If you quickly tap the button, the menu will be quickly displayed and then disappear. In this case, onWillDisappear may take effect before onDidAppear. 2. aboutToDisappear and onWillDisappear are invoked at the same time. onWillDisappear takes effect after aboutToDisappear. |
| onDidDisappear | Callback<void> | Callback invoked after the menu disappears. Note: onDisappear and onDidDisappear are triggered at the same time. onDidDisappear takes effect after onDisappear. |