searchInput in ngSelect can not auto focus

Published

I want trigger my searchInput in ngSelect auto focus but it doesn’t work. Below is my code.

File template

<span #addTopic class="w-100 d-block text-truncate" (click)="openDropdownTopic()">Add Topic</span>
<ng-select
  #dropdownTopic
  [items]="topics"
  [addTag]="true"
  class="ng-select ng-select-sm"
  bindLabel="name"
  bindValue="name"
  formControlName="name"
  addTagText="Add topic"
>
</ng-select>

File typescript

@ViewChild('addTopic') addTopic: ElementRef;
@ViewChild('dropdownTopic') dropdownTopic: NgSelectComponent;

openDropdownTopic() {
  this.dropdownTopic.open();
  this.dropdownTopic.searchInput.nativeElement.autofocus = true;
}

Details: When I click <span #addTopic> I want my ngSelect auto drop down and auto focus on input

Source: Angular Questions

Published
Categorized as angular, angular-ngselect, html, typescript Tagged , , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq