@@ -107,6 +107,8 @@ import ContextMenuSeparator from './ContextMenuSeparator.vue'
107107
108108// The internal info context for submenu instance
109109export interface SubMenuContext {
110+ name: Ref <string >,
111+ el: Ref <HTMLElement | undefined >;
110112 isTopLevel: () => boolean ;
111113 closeSelfAndActiveParent: () => boolean ,
112114 openCurrentItemSubMenu: () => boolean ,
@@ -219,6 +221,8 @@ const parentContext = inject('menuContext') as SubMenuParentContext;
219221const options = inject (' globalOptions' ) as Ref <MenuOptions >;
220222const globalHasSlot = inject (' globalHasSlot' ) as GlobalHasSlot ;
221223const globalRenderSlot = inject (' globalRenderSlot' ) as GlobalRenderSlot ;
224+ const debugMenuItemNameDefault = ref (' UnknowOrRoot' );
225+ const debugMenuItemName = inject <Ref <string >>(' MenuItemName' , debugMenuItemNameDefault );
222226
223227// #endregion
224228
@@ -283,6 +287,8 @@ function onSubMenuBodyClick() {
283287}
284288
285289const thisMenuInsContext : SubMenuContext = {
290+ el: menu ,
291+ name: debugMenuItemName ,
286292 isTopLevel : () => parentContext .getParentContext () === null ,
287293 closeSelfAndActiveParent : () => {
288294 const parent = thisMenuContext .getParentContext ();
@@ -518,16 +524,6 @@ function doAdjustPosition() {
518524 });
519525 }
520526
521- // Focus this submenu
522- menuEl ?.focus ({
523- preventScroll: true
524- });
525-
526- // Is this submenu opened by keyboard? If yes then select first item
527- if (parentContext .isOpenedByKeyBoardFlag ())
528- setAndFocusNotDisableItem (true );
529-
530- isMenuItemDataCollectedFlag = true ;
531527 });
532528}
533529
@@ -547,6 +543,22 @@ function showSolve() {
547543 position .value .x = x ;
548544 position .value .y = y ;
549545 }
546+ // Focus current
547+ nextTick (() => {
548+
549+ // Mark current item submenu is open
550+ globalSetCurrentSubMenu (thisMenuInsContext );
551+
552+ // Focus this submenu
553+ menu .value ?.focus ({ preventScroll: true });
554+
555+ // Is this submenu opened by keyboard? If yes then select first item
556+ if (parentContext .isOpenedByKeyBoardFlag ())
557+ nextTick (() => setAndFocusNotDisableItem (true ));
558+
559+ isMenuItemDataCollectedFlag = true ;
560+ });
561+ //
550562 doAdjustPosition ();
551563}
552564
@@ -556,9 +568,8 @@ watch(() => props.show, (v) => {
556568
557569onMounted (() => {
558570 mounted .value = true ;
559- // Mark current item submenu is open
560- globalSetCurrentSubMenu (thisMenuInsContext );
561- showSolve ();
571+ if (props .show )
572+ showSolve ();
562573});
563574onBeforeUnmount (() => {
564575 mounted .value = false ;
0 commit comments