Skip to content

Commit a6118f5

Browse files
committed
Fix MenuBar that do not emit onSubMenuOpen event
1 parent c2809bf commit a6118f5

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
# local env files
1212
.env.local
1313
.env.*.local
14+
.parcel-cache
1415

1516
# Log files
1617
npm-debug.log*

examples/views/MenuBar.vue

+6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ const menuData : MenuBarOptions = {
4343
{ label: "File 4...." },
4444
{ label: "File 5...." },
4545
],
46+
onSubMenuOpen(itemInstance) {
47+
console.log('onSubMenuOpen2', itemInstance);
48+
},
4649
},
4750
{ label: "Save", divided: true },
4851
{ label: "Save as..." },
4952
{ label: "Close" },
5053
{ label: "Exit" },
5154
],
55+
onSubMenuOpen(itemInstance) {
56+
console.log('onSubMenuOpen', itemInstance);
57+
},
5258
},
5359
{
5460
label: "Edit",

library/ContextMenuDefine.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,16 @@ export interface MenuItem {
480480
onClick ?: (e?: MouseEvent|KeyboardEvent) => void,
481481
/**
482482
* This event emit when submenu of this item is closing.
483+
*
484+
* @param itemInstance The instance of this submenu, undefined if in topmost level.
483485
*/
484-
onSubMenuClose ?: ((itemInstance: MenuItemContext) => void) | undefined;
486+
onSubMenuClose ?: ((itemInstance?: MenuItemContext) => void) | undefined;
485487
/**
486488
* This event emit when submenu of this item is showing.
489+
*
490+
* @param itemInstance The instance of this submenu, undefined if in topmost level.
487491
*/
488-
onSubMenuOpen ?: ((itemInstance: MenuItemContext) => void) | undefined;
492+
onSubMenuOpen ?: ((itemInstance?: MenuItemContext) => void) | undefined;
489493
/**
490494
* A custom render callback that allows you to customize the rendering
491495
* of the current item.

library/ContextSubMenu.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
<ContextMenuItem
3636
v-else
3737
:clickHandler="item.onClick ? (e) => item.onClick!(e) : undefined"
38-
:disabled="item.disabled"
39-
:hidden="item.hidden"
38+
:disabled="typeof item.disabled === 'object' ? item.disabled.value : item.disabled"
39+
:hidden="typeof item.hidden === 'object' ? item.hidden.value : item.hidden"
4040
:icon="item.icon"
4141
:iconFontClass="item.iconFontClass"
4242
:svgIcon="item.svgIcon"
4343
:svgProps="item.svgProps"
4444
:label="item.label"
4545
:customRender="(item.customRender as Function)"
4646
:customClass="item.customClass"
47-
:checked="item.checked"
47+
:checked="typeof item.checked === 'object' ? item.checked.value : item.checked"
4848
:shortcut="item.shortcut"
4949
:clickClose="item.clickClose"
5050
:clickableWhenHasChildren="item.clickableWhenHasChildren"
@@ -102,7 +102,7 @@
102102
</template>
103103

104104
<script lang="ts">
105-
import { defineComponent, inject, nextTick, onMounted, type PropType, provide, ref, toRefs, type Ref, onBeforeUnmount } from 'vue'
105+
import { defineComponent, inject, nextTick, onMounted, type PropType, provide, ref, toRefs, type Ref, onBeforeUnmount, type ComputedRef } from 'vue'
106106
import type { MenuOptions, MenuItem, ContextMenuPositionData, MenuPopDirection, MenuItemContext, ContextSubMenuInstance } from './ContextMenuDefine'
107107
import type { GlobalHasSlot, GlobalRenderSlot } from './ContextMenu.vue'
108108
import { MenuConstOptions } from './ContextMenuDefine'

library/MenuBar.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/**
4949
* Menu bar component
5050
*/
51-
import { ref, type PropType, onMounted, watch } from 'vue';
51+
import { ref, nextTick, type PropType, onMounted, watch } from 'vue';
5252
import type { MenuBarOptions } from './MenuBar';
5353
import type { ContextMenuInstance, MenuItem } from './ContextMenuDefine';
5454
import { getTop, getLeft } from './ContextMenuUtils';
@@ -151,8 +151,13 @@ function showSubMenu(index: number, item: MenuItem) {
151151
menuBarActive.value = false;
152152
menuActive.value = null;
153153
}
154+
if (typeof item.onSubMenuClose === 'function')
155+
item.onSubMenuClose(undefined);
154156
},
155157
});
158+
159+
if (currentMenu && typeof item.onSubMenuOpen === 'function')
160+
item.onSubMenuOpen(undefined);
156161
}
157162
}
158163
function showAllSubMenu() {

0 commit comments

Comments
 (0)