Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
Angular ngbDropdown: keyboard navigation not working

I have modal made of a search bar and a list of elements, created with a ngbDropdown splitted into 2 components, parent and child. It works correctly, but I can't figure out a way to enable navigation with keyboard (use UP & DOWN keys to move between list's elements).

Following the official documentation, I tried to use ngbDropdownItem, but it's not working.

These are my 2 component's templates:

  1. PARENT:

<div ngbDropdown class="dropdown-no-arrow" (openChange)="openChange($event)" container="body">

  <!-- trigger -->
  <ng-container>
    <button class="btn" ngbDropdownToggle *ngIf="authorizationService.loggedInUser">
      <i class="fal fa-farm me-2"></i>
      <span>{{ authorizationService.loggedInUser.name }}</span>
      <i class="fal fa-chevron-down ms-2"></i>
    </button>
  </ng-container>

  <!-- menu -->
  <div ngbDropdownMenu aria-labelledby="currentMenuItem" id="currentDropdown_{{ id }}">
    
    <button ngbDropdownItem (click)="openNewModal()">
      <i class="fal fa-plus me-1"></i> <span i18n>New</span>
    </button>

    <dm-child-list [isListDisplayed]="isDropdownOpened"></dm-child-list>
  </div>
</div>

  1. CHILD:

<div class="dropdown-header d-flex margin-x align-items-center">
  <h6 class=" mb-0 flex-grow-1" i18n>MY LIST</h6>
</div>
<div class="px-4 py-2">
  <div class="form-group mb-0">
    <input class="form-control form-control-sm" libAutofocus [(ngModel)]="elSearch" (ngModelChange)="elSearch$.next($event)" i18n-placeholder placeholder="Search elements">
  </div>
</div>

<button *ngFor="let el of list; let i = index;" ngbDropdownItem [ngClass]="{'top-border': i === 0}">
  <i class="me-2 fas fa-check-circle text-success"
     *ngIf="selectedEl?.id === el.id" title="Current element"></i>
  <i class="me-2 fal fa-circle" *ngIf="selectedEl?.id !== el.id"></i>
  <span>{{ el.name }}</span>
</button>

Can anyone help with making keyboard selection work?

Thanks!

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!