1- import { Component , Input , Output , EventEmitter , ChangeDetectionStrategy , ViewChild , ElementRef , Renderer2 , AfterViewInit , ChangeDetectorRef } from '@angular/core' ;
1+ import { Component , Input , Output , EventEmitter , ChangeDetectionStrategy , ElementRef , Renderer2 , AfterViewInit , ChangeDetectorRef , viewChild , inject } from '@angular/core' ;
22import { TranslatePipe } from '@ngx-translate/core' ;
33import { IconComponent } from '../icon/icon.component' ;
44
@@ -23,17 +23,21 @@ export class SearchComponent implements AfterViewInit {
2323 public inSearchMode : boolean ;
2424
2525 // Get access to the input to manipulate it.
26- @ ViewChild ( 'searchText' ) inputSearch : ElementRef ;
26+ public inputSearch = viewChild < ElementRef > ( 'searchText' ) ;
2727
28- @ ViewChild ( 'unoSearch' ) private readonly unoSearch : ElementRef ;
28+ private readonly unoSearch = viewChild < ElementRef > ( 'unoSearch' ) ;
2929
30- constructor ( private readonly renderer : Renderer2 , private readonly cdr : ChangeDetectorRef ) { }
30+ private readonly renderer = inject ( Renderer2 ) ;
31+
32+ private readonly cdr = inject ( ChangeDetectorRef ) ;
33+
34+ constructor ( ) { }
3135
3236 public ngAfterViewInit ( ) {
3337 if ( this . currentSearch && this . currentSearch . length > 0 ) {
3438 this . inSearchMode = true ;
35- this . renderer . setProperty ( this . inputSearch . nativeElement , 'value' , this . currentSearch ) ;
36- this . renderer . setStyle ( this . unoSearch . nativeElement , 'border-bottom' , '2px solid var(--light-primary)' ) ;
39+ this . renderer . setProperty ( this . inputSearch ( ) . nativeElement , 'value' , this . currentSearch ) ;
40+ this . renderer . setStyle ( this . unoSearch ( ) . nativeElement , 'border-bottom' , '2px solid var(--light-primary)' ) ;
3741 this . cdr . detectChanges ( ) ;
3842 }
3943 }
@@ -43,25 +47,25 @@ export class SearchComponent implements AfterViewInit {
4347 this . inSearchMode = ! this . inSearchMode ;
4448
4549 if ( ! this . inSearchMode ) {
46- this . renderer . setProperty ( this . inputSearch . nativeElement , 'value' , '' ) ;
50+ this . renderer . setProperty ( this . inputSearch ( ) . nativeElement , 'value' , '' ) ;
4751
48- if ( this . unoSearch ) {
49- this . renderer . setStyle ( this . unoSearch . nativeElement , 'border-bottom' , '2px solid var(--light-gray-12)' ) ;
52+ if ( this . unoSearch ( ) ) {
53+ this . renderer . setStyle ( this . unoSearch ( ) . nativeElement , 'border-bottom' , '2px solid var(--light-gray-12)' ) ;
5054 }
5155
5256 this . searchTerm . emit ( '' ) ;
5357 } else {
54- if ( this . unoSearch ) {
55- this . renderer . setStyle ( this . unoSearch . nativeElement , 'border-bottom' , '2px solid var(--light-primary)' ) ;
58+ if ( this . unoSearch ( ) ) {
59+ this . renderer . setStyle ( this . unoSearch ( ) . nativeElement , 'border-bottom' , '2px solid var(--light-primary)' ) ;
5660 }
5761
5862 this . searchTerm . emit ( text ) ;
5963 }
6064 } else {
6165 this . inSearchMode = false ;
6266
63- if ( this . unoSearch ) {
64- this . renderer . setStyle ( this . unoSearch . nativeElement , 'border-bottom' , '2px solid var(--light-gray-12)' ) ;
67+ if ( this . unoSearch ( ) ) {
68+ this . renderer . setStyle ( this . unoSearch ( ) . nativeElement , 'border-bottom' , '2px solid var(--light-gray-12)' ) ;
6569 }
6670
6771 this . searchTerm . emit ( '' ) ;
@@ -76,14 +80,14 @@ export class SearchComponent implements AfterViewInit {
7680 if ( text . length > 0 ) {
7781 this . inSearchMode = true ;
7882
79- if ( this . unoSearch ) {
80- this . renderer . setStyle ( this . unoSearch . nativeElement , 'border-bottom' , '2px solid var(--light-primary)' ) ;
83+ if ( this . unoSearch ( ) ) {
84+ this . renderer . setStyle ( this . unoSearch ( ) . nativeElement , 'border-bottom' , '2px solid var(--light-primary)' ) ;
8185 }
8286 } else {
8387 this . inSearchMode = false ;
8488
85- if ( this . unoSearch ) {
86- this . renderer . setStyle ( this . unoSearch . nativeElement , 'border-bottom' , '2px solid var(--light-gray-12)' ) ;
89+ if ( this . unoSearch ( ) ) {
90+ this . renderer . setStyle ( this . unoSearch ( ) . nativeElement , 'border-bottom' , '2px solid var(--light-gray-12)' ) ;
8791 }
8892 }
8993 }
0 commit comments