nebular icon indicating copy to clipboard operation
nebular copied to clipboard

How can I prevent parent element click to call NbMenuService click

Open Gumichocopengin8 opened this issue 5 years ago • 1 comments

<div (click)="click()">
  <div [nbContextMenu]="context"></div>
<div>
ngOnInit() {
    this.nbMenu
      .onItemClick() something execute
}

When I click menu button to open menu, parent click is called. I tried to use stopPropagation(), but not worked.

How can I prevent to call parent click? Thank you.

Gumichocopengin8 avatar Jan 28 '20 22:01 Gumichocopengin8

Found a way to handle it:

initial structure:

<div class="parent" (click)="doSomething()">
    <div class="menu-button-inside-parent" [nbContextMenu]="context"></div>
    <div class="content-inside-parent"></div>
</div>

change the structure to the one, where the click event is handled by the other element inside the parent and so that it takes the whole space of the parent (important to put "position: absolute" for the menu trigger button container) , like this:

<div class="parent">
    <div class="menu-button-inside-parent" [nbContextMenu]="context" style="position: absolute"></div>
    <div class="click-handler"
         style="width: 100%; height: 100%; z-index: 0"
         (click)="doSomething()">
        <div class="content-inside-parent" ></div>
    </div>
</div>

luaroncrew avatar Aug 23 '23 14:08 luaroncrew