Skip to content

Commit

Permalink
docs: add autofocus for overview page search-input (#5648)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz authored Sep 8, 2020
1 parent 57962e1 commit 2565c19
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
Expand All @@ -15,6 +15,7 @@ export class ComponentsOverviewComponent implements OnInit {
routerList = ROUTER_LIST;
language = 'en';
searchChange$ = new BehaviorSubject('');
@ViewChild('searchBox', { static: true }) searchBox!: ElementRef<HTMLInputElement>;

constructor(private route: ActivatedRoute, private cdr: ChangeDetectorRef) {}

Expand All @@ -30,6 +31,11 @@ export class ComponentsOverviewComponent implements OnInit {
.subscribe((searchValue: string) => {
this.filterComponents(searchValue);
});

// autofocus
Promise.resolve().then(() => {
this.searchBox.nativeElement.focus();
});
}

onSearch(searchValue: string): void {
Expand Down

0 comments on commit 2565c19

Please sign in to comment.