ng-bootstrap
ng-bootstrap copied to clipboard
`[autoClose]` for `ngbDropdown` is not working with right click
Bug or feature description:
Right-click does not close ngbDropdown
with [autoClose]=true
.
<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:
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
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.
I also found a need for this autoclose on the right-click feature. @vladkasianenko have you found a walkaround?