ng-bootstrap icon indicating copy to clipboard operation
ng-bootstrap copied to clipboard

`[autoClose]` for `ngbDropdown` is not working with right click

Open vladkasianenko opened this issue 1 year ago • 2 comments

Bug or feature description:

Right-click does not close ngbDropdown with [autoClose]=true. image

<div ngbDropdown
     [autoClose]="true"
     #customContextMenu="ngbDropdown"
     (contextmenu)="$event.preventDefault(); customContextMenu.open()">
           
  <!-- other HTML content -->

  <div ngbDropdownMenu>
    <button ngbDropdownItem>Action 1</button>
    <button ngbDropdownItem>Action 2</button>
    <div class="dropdown-divider"></div>
    <button ngbDropdownItem>Action 3</button>
  </div>
</div>

I'm opening dropdown to imitate a context menu, but when I right-click on another element to also open a context menu, the previous one is not closed. I'm not sure if it's a bug, since you can do something like that: image

So maybe it should listen to more events than here? https://github.com/ng-bootstrap/ng-bootstrap/blob/9ba97451e709c71eedd8c49caf8994ae0d8aa19e/src/util/autoclose.ts#L33

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 16.2.12

ng-bootstrap: 15.1.2

Bootstrap: 5.2.3

vladkasianenko avatar Nov 05 '23 19:11 vladkasianenko

It is not a bug to my knowledge, but the explicit decision. I'll mark this as a feature request to better customize autoclosing behavior.

maxokorokov avatar Nov 13 '23 13:11 maxokorokov

I also found a need for this autoclose on the right-click feature. @vladkasianenko have you found a walkaround?

ankit9015 avatar May 09 '24 13:05 ankit9015