diff --git a/src/components/context-menu/context-menu.ts b/src/components/context-menu/context-menu.ts index 630b44f4c..3cf987667 100644 --- a/src/components/context-menu/context-menu.ts +++ b/src/components/context-menu/context-menu.ts @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core'; +import { Component, Input, OnInit, OnDestroy, ElementRef, Optional } from '@angular/core'; import { PopoverController } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreContextMenuItemComponent } from './context-menu-item'; import { CoreContextMenuPopoverComponent } from './context-menu-popover'; +import { CoreTabComponent } from '@components/tabs/tab'; import { Subject } from 'rxjs'; /** @@ -40,7 +41,7 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy { protected parentContextMenu: CoreContextMenuComponent; constructor(private translate: TranslateService, private popoverCtrl: PopoverController, elementRef: ElementRef, - private domUtils: CoreDomUtilsProvider) { + private domUtils: CoreDomUtilsProvider, @Optional() public coreTab: CoreTabComponent) { // Create the stream and subscribe to it. We ignore successive changes during 250ms. this.itemsChangedStream = new Subject(); this.itemsChangedStream.auditTime(250).subscribe(() => { diff --git a/src/components/navbar-buttons/navbar-buttons.ts b/src/components/navbar-buttons/navbar-buttons.ts index d682248a6..7f4ae239b 100644 --- a/src/components/navbar-buttons/navbar-buttons.ts +++ b/src/components/navbar-buttons/navbar-buttons.ts @@ -134,10 +134,12 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy { } // Both containers have a context menu. Merge them to prevent having 2 menus at the same time. - const mainContextMenuInstance = this.domUtils.getInstanceByElement(mainContextMenu), - secondaryContextMenuInstance = this.domUtils.getInstanceByElement(secondaryContextMenu); + const mainContextMenuInstance: CoreContextMenuComponent = this.domUtils.getInstanceByElement(mainContextMenu), + secondaryContextMenuInstance: CoreContextMenuComponent = this.domUtils.getInstanceByElement(secondaryContextMenu); - if (mainContextMenuInstance && secondaryContextMenuInstance) { + // Check that both context menus belong to the same core-tab. We shouldn't merge menus from different tabs. + if (mainContextMenuInstance && secondaryContextMenuInstance && + mainContextMenuInstance.coreTab === secondaryContextMenuInstance.coreTab) { this.mergedContextMenu = secondaryContextMenuInstance; this.mergedContextMenu.mergeContextMenus(mainContextMenuInstance);