1e41f4b71Sopenharmony_ci# Menu
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Menu** component is a vertical list of items presented to the user.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - This component is supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> - The **Menu** component must be used together with the [bindMenu](ts-universal-attributes-menu.md#bindmenu) or [bindContextMenu](ts-universal-attributes-menu.md#bindcontextmenu8) method. It does not work when used alone.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Child Components
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciThis component contains the [MenuItem](ts-basic-components-menuitem.md) and [MenuItemGroup](ts-basic-components-menuitemgroup.md) child components.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciMenu()
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciCreates a fixed container for a menu. This API does not have any parameters.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci> **NOTE**
22e41f4b71Sopenharmony_ci> Rules for calculating the width of menus and menu items:
23e41f4b71Sopenharmony_ci>
24e41f4b71Sopenharmony_ci> During the layout, the width of each menu item is expected to be the same. If a child component has its width set, the [size calculation rule](ts-universal-attributes-size.md#constraintsize) prevails.
25e41f4b71Sopenharmony_ci>
26e41f4b71Sopenharmony_ci> If the width is not set, the **Menu** component sets the default width of two columns for the **MenuItem** and **MenuItemGroup** child components. If a menu item's content area is wider than two columns, the **Menu** component automatically expands the menu item content area.
27e41f4b71Sopenharmony_ci>
28e41f4b71Sopenharmony_ci> When the width is set, the **Menu** component sets the **MenuItem** and **MenuItemGroup** child components to the fixed width (set width minus the padding).
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci## subMenuExpandingMode<sup>12+</sup>
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ciEnumerates the submenu expanding modes.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| Name          | Description                               |
39e41f4b71Sopenharmony_ci|--------------|-----------------------------------|
40e41f4b71Sopenharmony_ci| SIDE_EXPAND  | Default mode. Submenus are expanded on the side on the same plane.           |
41e41f4b71Sopenharmony_ci| EMBEDDED_EXPAND | Embedded mode. Submenus are expanded while embedded within the main menu.             |
42e41f4b71Sopenharmony_ci| STACK_EXPAND | Stack mode. Submenus are expanded above the main menu. |
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci## Attributes
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci### fontSize<sup>(deprecated)</sup>
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_cifontSize(value: Length)
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ciSets the size of all text within the menu.
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciThis API is deprecated since API version 10. You are advised to use [font](#font10) instead.
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Parameters**
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci| Name | Type                        | Mandatory | Description                                                    |
61e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | -------------------------------------------------------- |
62e41f4b71Sopenharmony_ci| value  | [Length](ts-types.md#length) | Yes  | Size of all text within the menu. If the value of the Length type is a number, the unit is fp. |
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci### font<sup>10+</sup>
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_cifont(value: Font)
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciSets the size of all text within the menu.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Parameters**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| Name | Type                    | Mandatory | Description                  |
77e41f4b71Sopenharmony_ci| ------ | ------------------------ | ---- | ---------------------- |
78e41f4b71Sopenharmony_ci| value  | [Font](ts-types.md#font) | Yes  | Size of all text within the menu. |
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci### fontColor<sup>10+</sup>
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_cifontColor(value: ResourceColor)
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ciSets the font color of all text within the menu.
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Parameters**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| Name | Type                                      | Mandatory | Description                  |
93e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------------------- |
94e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Font color of all text within the menu. |
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci### radius<sup>10+</sup>
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ciradius(value: Dimension | BorderRadiuses)
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciSets the radius of the menu border corners.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**Parameters**
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                                                        |
109e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
110e41f4b71Sopenharmony_ci| value  | [Dimension](ts-types.md#dimension10) \| [BorderRadiuses](ts-types.md#borderradiuses9) | Yes  | Radius of the menu border corners.<br> The default value follows the theme.<br> Since API version 12, if the sum of the two maximum corner radii in the horizontal direction exceeds the menu's width, or if the sum of the two maximum corner radii in the vertical direction exceeds the menu's height, the default corner radius will be used for all four corners of the menu. |
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci### width<sup>10+</sup>
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ciwidth(value: Length)
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ciSets the border width of the menu. The minimum width is 64 vp.
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10.
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**Parameters**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci| Name | Type                        | Mandatory | Description          |
125e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | -------------- |
126e41f4b71Sopenharmony_ci| value  | [Length](ts-types.md#length) | Yes  | Border width of the menu. |
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci### menuItemDivider<sup>12+</sup>
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_cimenuItemDivider(options: DividerStyleOptions | undefined)
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ciSets the style of the menu item divider. If this attribute is not set, the divider will not be displayed.
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ciIf the sum of **startMargin** and **endMargin** exceeds the component width, both **startMargin** and **endMargin** will be set to **0**.
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci**Parameters**
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci| Name    | Type                                                    | Mandatory        | Description          |
143e41f4b71Sopenharmony_ci|---------|--------------------------------------------------------|------------| -------------- |
144e41f4b71Sopenharmony_ci| options | [DividerStyleOptions](ts-types.md#dividerstyleoptions12) \|  undefined | Yes  | Style of the menu item divider.<br>- **strokeWidth**: stroke width of the divider.<br>- **color**: color of the divider.<br>- **startMargin**: distance between the divider and the start edge of the menu item.<br>- **endMargin**: distance between the divider and the end edge of the menu item. |
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci### menuItemGroupDivider<sup>12+</sup>
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_cimenuItemGroupDivider(options: DividerStyleOptions | undefined)
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ciSets the style of the top and bottom dividers for the menu item group. If this attribute is not set, the dividers will be displayed by default.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**Parameters**
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci| Name    | Type                                                    | Mandatory        | Description          |
159e41f4b71Sopenharmony_ci|---------|--------------------------------------------------------|------------| -------------- |
160e41f4b71Sopenharmony_ci| options | [DividerStyleOptions](ts-types.md#dividerstyleoptions12) \|  undefined | Yes  | Style of the top and bottom dividers for the menu item group.<br>- **strokeWidth**: stroke width of the divider. The default value is 1 px.<br>- **color**: color of the divider. The default value is **#33000000**.<br>- **startMargin**: distance between the divider and the start edge of the menu item group. The default value is **16**.<br>- **endMargin**: distance between the divider and the end edge of the menu item group. The default value is **16**. |
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci### subMenuExpandingMode<sup>12+</sup>
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_cisubMenuExpandingMode(mode: SubMenuExpandingMode)
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciSets the submenu expanding mode of the menu.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**Parameters**
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci| Name | Type                        | Mandatory | Description          |
175e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- |--------------|
176e41f4b71Sopenharmony_ci| mode  | SubMenuExpandingMode | Yes  | Submenu expanding mode of the menu. |
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci## Example
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci### Example 1
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci```ts
183e41f4b71Sopenharmony_ci@Entry
184e41f4b71Sopenharmony_ci@Component
185e41f4b71Sopenharmony_cistruct Index {
186e41f4b71Sopenharmony_ci  @State select: boolean = true
187e41f4b71Sopenharmony_ci  private iconStr: ResourceStr = $r("app.media.view_list_filled")
188e41f4b71Sopenharmony_ci  private iconStr2: ResourceStr = $r("app.media.arrow_right_filled")
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci  @Builder
191e41f4b71Sopenharmony_ci  SubMenu() {
192e41f4b71Sopenharmony_ci    Menu() {
193e41f4b71Sopenharmony_ci      MenuItem({ content: "Copy", labelInfo: "Ctrl+C" })
194e41f4b71Sopenharmony_ci      MenuItem({ content: "Paste", labelInfo: "Ctrl+V" })
195e41f4b71Sopenharmony_ci    }
196e41f4b71Sopenharmony_ci  }
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci  @Builder
199e41f4b71Sopenharmony_ci  MyMenu(){
200e41f4b71Sopenharmony_ci    Menu() {
201e41f4b71Sopenharmony_ci      MenuItem({ startIcon: $r("app.media.icon"), content: "Menu item" })
202e41f4b71Sopenharmony_ci      MenuItem({ startIcon: $r("app.media.icon"), content: "Menu item" })
203e41f4b71Sopenharmony_ci        .enabled(false)
204e41f4b71Sopenharmony_ci      MenuItem({
205e41f4b71Sopenharmony_ci        startIcon: this.iconStr,
206e41f4b71Sopenharmony_ci        content: "Menu item",
207e41f4b71Sopenharmony_ci        endIcon: this.iconStr2,
208e41f4b71Sopenharmony_ci        builder: ():void=>this.SubMenu()
209e41f4b71Sopenharmony_ci      })
210e41f4b71Sopenharmony_ci      MenuItemGroup({ header: 'Subtitle' }) {
211e41f4b71Sopenharmony_ci        MenuItem({
212e41f4b71Sopenharmony_ci          startIcon: this.iconStr,
213e41f4b71Sopenharmony_ci          content: "Menu item",
214e41f4b71Sopenharmony_ci          endIcon: this.iconStr2,
215e41f4b71Sopenharmony_ci          builder: ():void=>this.SubMenu()
216e41f4b71Sopenharmony_ci        })
217e41f4b71Sopenharmony_ci        MenuItem({
218e41f4b71Sopenharmony_ci          startIcon: $r("app.media.app_icon"),
219e41f4b71Sopenharmony_ci          content: "Menu item",
220e41f4b71Sopenharmony_ci          endIcon: this.iconStr2,
221e41f4b71Sopenharmony_ci          builder: ():void=>this.SubMenu()
222e41f4b71Sopenharmony_ci        })
223e41f4b71Sopenharmony_ci      }
224e41f4b71Sopenharmony_ci      MenuItem({
225e41f4b71Sopenharmony_ci        startIcon: this.iconStr,
226e41f4b71Sopenharmony_ci        content: "Menu item",
227e41f4b71Sopenharmony_ci      })
228e41f4b71Sopenharmony_ci    }
229e41f4b71Sopenharmony_ci  }
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci  build() {
232e41f4b71Sopenharmony_ci    Row() {
233e41f4b71Sopenharmony_ci      Column() {
234e41f4b71Sopenharmony_ci        Text('click to show menu')
235e41f4b71Sopenharmony_ci          .fontSize(50)
236e41f4b71Sopenharmony_ci          .fontWeight(FontWeight.Bold)
237e41f4b71Sopenharmony_ci      }
238e41f4b71Sopenharmony_ci      .bindMenu(this.MyMenu)
239e41f4b71Sopenharmony_ci      .width('100%')
240e41f4b71Sopenharmony_ci    }
241e41f4b71Sopenharmony_ci    .height('100%')
242e41f4b71Sopenharmony_ci  }
243e41f4b71Sopenharmony_ci}
244e41f4b71Sopenharmony_ci```
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci![menu1](figures/menu1.png)
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci### Example 2
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ciThis example demonstrates a regular menu (using symbol-type icons).
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci```ts
253e41f4b71Sopenharmony_ci// xxx.ets
254e41f4b71Sopenharmony_ciimport { SymbolGlyphModifier } from '@kit.ArkUI';
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci@Entry
257e41f4b71Sopenharmony_ci@Component
258e41f4b71Sopenharmony_cistruct Index {
259e41f4b71Sopenharmony_ci  @State startIconModifier: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_mic')).fontSize('24vp');
260e41f4b71Sopenharmony_ci  @State endIconModifier: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_trash')).fontSize('24vp');
261e41f4b71Sopenharmony_ci  @State selectIconModifier: SymbolGlyphModifier =
262e41f4b71Sopenharmony_ci    new SymbolGlyphModifier($r('sys.symbol.checkmark')).fontSize('24vp');
263e41f4b71Sopenharmony_ci  @State select: boolean = true;
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci  @Builder
266e41f4b71Sopenharmony_ci  SubMenu() {
267e41f4b71Sopenharmony_ci    Menu() {
268e41f4b71Sopenharmony_ci      MenuItem({ content: "Copy", labelInfo: "Ctrl+C" })
269e41f4b71Sopenharmony_ci      MenuItem({ content: "Paste", labelInfo: "Ctrl+V" })
270e41f4b71Sopenharmony_ci    }
271e41f4b71Sopenharmony_ci  }
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci  @Builder
274e41f4b71Sopenharmony_ci  MyMenu() {
275e41f4b71Sopenharmony_ci    Menu() {
276e41f4b71Sopenharmony_ci      MenuItem({ symbolStartIcon: this.startIconModifier, content: "Menu item" })
277e41f4b71Sopenharmony_ci      MenuItem({ symbolStartIcon: this.startIconModifier, content: "Menu item" })
278e41f4b71Sopenharmony_ci        .enabled(false)
279e41f4b71Sopenharmony_ci      MenuItem({
280e41f4b71Sopenharmony_ci        symbolStartIcon: this.startIconModifier,
281e41f4b71Sopenharmony_ci        content: "Menu item",
282e41f4b71Sopenharmony_ci        symbolEndIcon: this.endIconModifier,
283e41f4b71Sopenharmony_ci        builder: (): void => this.SubMenu()
284e41f4b71Sopenharmony_ci      })
285e41f4b71Sopenharmony_ci      MenuItemGroup({ header: 'Subtitle' }) {
286e41f4b71Sopenharmony_ci        MenuItem({
287e41f4b71Sopenharmony_ci          symbolStartIcon: this.startIconModifier,
288e41f4b71Sopenharmony_ci          content: "Menu item",
289e41f4b71Sopenharmony_ci          symbolEndIcon: this.endIconModifier,
290e41f4b71Sopenharmony_ci          builder: (): void => this.SubMenu()
291e41f4b71Sopenharmony_ci        })
292e41f4b71Sopenharmony_ci        MenuItem({
293e41f4b71Sopenharmony_ci          symbolStartIcon: this.startIconModifier,
294e41f4b71Sopenharmony_ci          content: "Menu item",
295e41f4b71Sopenharmony_ci          symbolEndIcon: this.endIconModifier,
296e41f4b71Sopenharmony_ci          builder: (): void => this.SubMenu()
297e41f4b71Sopenharmony_ci        })
298e41f4b71Sopenharmony_ci      }
299e41f4b71Sopenharmony_ci      MenuItem({
300e41f4b71Sopenharmony_ci        content: "Menu item",
301e41f4b71Sopenharmony_ci      }).selected(this.select).selectIcon(this.selectIconModifier)
302e41f4b71Sopenharmony_ci    }
303e41f4b71Sopenharmony_ci  }
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci  build() {
306e41f4b71Sopenharmony_ci    Row() {
307e41f4b71Sopenharmony_ci      Column() {
308e41f4b71Sopenharmony_ci        Text('click to show menu')
309e41f4b71Sopenharmony_ci          .fontSize(50)
310e41f4b71Sopenharmony_ci          .fontWeight(FontWeight.Bold)
311e41f4b71Sopenharmony_ci      }
312e41f4b71Sopenharmony_ci      .bindMenu(this.MyMenu)
313e41f4b71Sopenharmony_ci      .width('100%')
314e41f4b71Sopenharmony_ci    }
315e41f4b71Sopenharmony_ci    .height('100%')
316e41f4b71Sopenharmony_ci  }
317e41f4b71Sopenharmony_ci}
318e41f4b71Sopenharmony_ci```
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci![en-us_image_0000001174582862](figures/normal-symbol.jpg)
321