@@ -22,6 +22,7 @@ import {
2222} from '@angular/core' ;
2323import { takeUntilDestroyed , toObservable , toSignal } from '@angular/core/rxjs-interop' ;
2424import { NgControl } from '@angular/forms' ;
25+ import { FORM_FIELD } from '@angular/forms/signals' ;
2526import { EMPTY } from 'rxjs' ;
2627import { map , startWith } from 'rxjs/operators' ;
2728
@@ -56,6 +57,7 @@ const PREFIX_CLS = 'ant-input';
5657 '[class.ant-input-sm]' : `finalSize() === 'small'` ,
5758 '[attr.disabled]' : 'finalDisabled() || null' ,
5859 '[attr.readonly]' : 'readonly() || null' ,
60+ '(input)' : 'onInput($event)' ,
5961 '[class.ant-input-rtl]' : `dir() === 'rtl'` ,
6062 '[class.ant-input-focused]' : 'focused()'
6163 } ,
@@ -72,9 +74,16 @@ export class NzInputDirective implements OnInit {
7274 private hostView = inject ( ViewContainerRef ) ;
7375 private readonly inputPasswordDir = inject ( NzInputPasswordDirective , { host : true , optional : true } ) ;
7476 private readonly inputSearchDir = inject ( NZ_INPUT_SEARCH , { host : true , optional : true } ) ;
77+ private readonly formField = inject ( FORM_FIELD , { self : true , optional : true } ) ;
7578
7679 readonly ngControl = inject ( NgControl , { self : true , optional : true } ) ;
77- readonly value = signal < string > ( this . elementRef . nativeElement . value ) ;
80+ private readonly nativeValue = signal ( this . elementRef . nativeElement . value ) ;
81+ readonly value = computed ( ( ) => {
82+ if ( this . formField ) {
83+ return String ( this . formField . state ( ) . value ( ) ?? '' ) ;
84+ }
85+ return this . nativeValue ( ) ;
86+ } ) ;
7887
7988 readonly nzVariant = input < NzVariant > ( ) ;
8089 readonly nzSize = input < NzSizeLDSType > ( 'default' ) ;
@@ -83,7 +92,12 @@ export class NzInputDirective implements OnInit {
8392 readonly readonly = input ( false , { transform : booleanAttribute } ) ;
8493
8594 readonly controlDisabled = signal ( false ) ;
86- readonly finalDisabled = this . ngControl ? this . controlDisabled : this . disabled ;
95+ readonly finalDisabled = computed ( ( ) => {
96+ if ( this . formField ) {
97+ return this . formField . state ( ) . disabled ( ) ;
98+ }
99+ return this . ngControl ? this . controlDisabled ( ) : this . disabled ( ) ;
100+ } ) ;
87101 readonly dir = inject ( Directionality ) . valueSignal ;
88102 // TODO: When the input group is removed, we can remove this.
89103 readonly size = linkedSignal ( this . nzSize ) ;
@@ -150,10 +164,14 @@ export class NzInputDirective implements OnInit {
150164 this . ngControl ?. valueChanges
151165 ?. pipe ( startWith ( this . ngControl ?. control ?. value ) , takeUntilDestroyed ( this . destroyRef ) )
152166 . subscribe ( value => {
153- this . value . set ( value ?? '' ) ;
167+ this . nativeValue . set ( value ?? '' ) ;
154168 } ) ;
155169 }
156170
171+ onInput ( event : Event ) : void {
172+ this . nativeValue . set ( ( event . target as HTMLInputElement | HTMLTextAreaElement ) . value ) ;
173+ }
174+
157175 private renderFeedbackIcon ( ) : void {
158176 if ( ! this . status ( ) || ! this . hasFeedback ( ) || this . inputWrapper ) {
159177 // remove feedback
0 commit comments