diff --git a/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md b/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md index 821bad6125b810a5cceb8a999f9e6af219f9945c..127299e7b6b705b8d4db132107eb586ba40ee71c 100644 --- a/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md +++ b/zh-cn/application-dev/reference/arkui-ts/Readme-CN.md @@ -138,5 +138,6 @@ - [自定义弹窗](ts-methods-custom-dialog-box.md) - [日期时间选择弹窗](ts-methods-datepicker-dialog.md) - [文本选择弹窗](ts-methods-textpicker-dialog.md) + - [菜单](ts-methods-menu.md) - 附录 - [文档中涉及到的内置枚举值](ts-appendix-enums.md) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-methods-menu.md b/zh-cn/application-dev/reference/arkui-ts/ts-methods-menu.md new file mode 100644 index 0000000000000000000000000000000000000000..df97249f6d38576b79f604df4aab7d277c7118f9 --- /dev/null +++ b/zh-cn/application-dev/reference/arkui-ts/ts-methods-menu.md @@ -0,0 +1,39 @@ +# 菜单 + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 + +## ContextMenu.close + +close(): void + +可以通过该方法在页面范围内关闭通过[bindContextMenu](./ts-universal-attributes-menu.md#属性)给组件绑定的菜单。 + +- 示例 + ``` + @Entry + @Component + struct Index { + @Builder MenuBuilder(){ + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('close') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + ContextMenu.close(); + }) + }.height(400) + .backgroundColor(Color.Pink) + + } + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { + Column(){ + Text("Text") + }.bindContextMenu(this.MenuBuilder, ResponseType.LongPress) + } + .width('100%') + .height('100%') + } + } + ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md index ba903b5b7674fbf3a3e5d8639a807b520e25507c..71c1273bb276dca02d9708a0bbd85601c98f1a31 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md @@ -15,7 +15,7 @@ | 名称 | 参数类型 | 默认值 | 描述 | | -------- | -------- | -------- | -------- | | bindMenu | Array8+ | - | 给组件绑定菜单,点击后弹出菜单。弹出菜单项支持文本和自定义两种功能。 | -| bindContextMenu | content: [CustomBuilder](../../ui/ts-types.md)8+
responseType: ResponseType8+ | - | 给组件绑定菜单,触发方式为长按或者右键点击,弹出菜单项需要自定义。 | +| bindContextMenu8+ | content: [CustomBuilder](../../ui/ts-types.md)
responseType: ResponseType | - | 给组件绑定菜单,触发方式为长按或者右键点击,弹出菜单项需要自定义。 | - MenuItem @@ -27,11 +27,13 @@ - ResponseType8+ | 参数值 | 描述 | | -------- | -------- | - | LongPress | 通过长按触发菜单弹出 | - | RightClick | 通过鼠标右键触发菜单弹出 | + | LongPress | 通过长按触发菜单弹出。 | + | RightClick | 通过鼠标右键触发菜单弹出。 | ## 示例 +#### 普通菜单 + ``` @Entry @Component @@ -62,6 +64,8 @@ struct MenuExample { ![zh-cn_image_0000001174582862](figures/zh-cn_image_0000001174582862.gif) +#### 自定义内容菜单 + ``` import router from '@system.router'; @@ -110,10 +114,12 @@ struct MenuExample { ![zh-cn_image_0000001186807708](figures/zh-cn_image_0000001186807708.gif) +#### 菜单(右键触发显示) + ``` @Entry @Component -struct MenuExample { +struct ContextMenuExample { @Builder MenuBuilder() { Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Text('Test menu item 1') @@ -129,6 +135,7 @@ struct MenuExample { .textAlign(TextAlign.Center) }.width(100) } + build() { Column() { Text('rightclick for menu')