Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda