Skip to content

Commit

Permalink
fix: Prevent several instances of a sub menu when opening with the mo…
Browse files Browse the repository at this point in the history
…use 2nd try
  • Loading branch information
sroucheray committed Mar 8, 2024
1 parent e4e9b3d commit e389d11
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ export class ContextMenuContentComponent<T>
subMenu: ContextMenuComponent<T> | undefined,
event: MouseEvent | KeyboardEvent
): void {
if (!subMenu || subMenu.isOpen) {
if (!subMenu) {
return;
}

if (this.focusKeyManager?.activeItemIndex === null || !subMenu) {
if (this.focusKeyManager?.activeItemIndex === null) {
return;
}

Expand All @@ -265,21 +265,31 @@ export class ContextMenuContentComponent<T>
value: this.value,
parentContextMenu: this,
});
} else if (event.currentTarget) {

return;
}

if (subMenu.isOpen) {
return;
}

if (event.currentTarget) {
subMenu.show({
anchoredTo: 'element',
anchorElement: event.currentTarget,
value: this.value,
parentContextMenu: this,
});
} else {
subMenu.show({
anchoredTo: 'position',
x: (event as MouseEvent).clientX,
y: (event as MouseEvent).clientY,
value: this.value,
});

return;
}

subMenu.show({
anchoredTo: 'position',
x: (event as MouseEvent).clientX,
y: (event as MouseEvent).clientY,
value: this.value,
});
}

/**
Expand Down Expand Up @@ -342,7 +352,8 @@ export class ContextMenuContentComponent<T>
}

private closeActiveItemSubMenu(event: KeyboardEvent) {
if (this.focusKeyManager?.activeItemIndex === null) {
this.hideSubMenus();
if (!this.focusKeyManager?.activeItemIndex) {
return;
}

Expand Down

0 comments on commit e389d11

Please sign in to comment.