11import {
22 booleanAttribute ,
33 ChangeDetectionStrategy ,
4+ ChangeDetectorRef ,
45 Component ,
56 ElementRef ,
67 forwardRef ,
8+ inject ,
79 Input ,
810 OnDestroy ,
911 OnInit ,
@@ -30,21 +32,42 @@ export const SEARCH_CONTROL_VALUE_ACCESSOR = {
3032 providers : [ SEARCH_CONTROL_VALUE_ACCESSOR ] ,
3133} )
3234export class SearchComponent implements OnInit , OnDestroy , ControlValueAccessor {
33- @Input ( ) value : string = '' ;
3435 @Input ( ) placeholder : string = 'Search...' ;
3536 @Input ( ) focusKey : string = '/' ;
3637 @Input ( { transform : booleanAttribute } ) focusKeyEnabled : boolean = true ;
37- @Input ( { transform : booleanAttribute } ) disabled : boolean = false ;
3838 @Input ( { transform : booleanAttribute } ) slim : boolean = false ;
3939 @ViewChild ( 'input' ) _inputElement ! : ElementRef < HTMLInputElement > ;
4040
4141 protected _onChange : ( value : string ) => void = noop ;
4242 protected _onTouched : ( ) => void = noop ;
4343
44+ private _value : string = '' ;
45+ private _disabled : boolean = false ;
46+
47+ @Input ( )
48+ get value ( ) : string {
49+ return this . _value ;
50+ }
51+ set value ( value : string ) {
52+ this . _value = value ;
53+ this . _changeDetectorRef . markForCheck ( ) ;
54+ }
55+
56+ @Input ( { transform : booleanAttribute } )
57+ get disabled ( ) : boolean {
58+ return this . _disabled ;
59+ }
60+ set disabled ( disabled : boolean ) {
61+ this . _disabled = disabled ;
62+ this . _changeDetectorRef . markForCheck ( ) ;
63+ }
64+
65+ private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
4466 private searchSubject : Subject < string > = new Subject ( ) ;
4567
4668 ngOnInit ( ) : void {
4769 this . searchSubject . pipe ( debounceTime ( 200 ) ) . subscribe ( ( value ) => {
70+ this . value = value ;
4871 this . _onChange ( value ) ;
4972 } ) ;
5073
@@ -78,12 +101,18 @@ export class SearchComponent implements OnInit, OnDestroy, ControlValueAccessor
78101 }
79102
80103 protected _onBlur ( ) : void {
81- Promise . resolve ( ) . then ( ( ) => this . _onTouched ( ) ) ;
104+ Promise . resolve ( ) . then ( ( ) => {
105+ this . _onTouched ( ) ;
106+ this . _changeDetectorRef . markForCheck ( ) ;
107+ } ) ;
108+ }
109+
110+ protected _onInputEvent ( ) : void {
111+ this . searchSubject . next ( this . _inputElement . nativeElement . value ) ;
82112 }
83113
84114 protected _onInteractionEvent ( event : Event ) : void {
85115 event . stopPropagation ( ) ;
86- this . searchSubject . next ( this . _inputElement . nativeElement . value ) ;
87116 }
88117
89118 protected _onKeyEvent ( event : KeyboardEvent ) : void {
0 commit comments