ng-bootstrap / ng-bootstrap/ng-bootstrap
`[autoClose]` for `ngbDropdown` is not working with right click
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.2k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/util/autoclose.ts at the linked event-handling logic, then reproduce the two-context-menu example from the issue. Check how right-click events are treated when [autoClose]="true" and verify the expected behavior with the existing dropdown tests. Done means opening another context menu by right-click closes the previously open ngbDropdown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, bootstrap, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100