@@ -15,6 +15,7 @@ import {
15
15
EventEmitter ,
16
16
forwardRef ,
17
17
Input ,
18
+ NgZone ,
18
19
OnChanges ,
19
20
OnDestroy ,
20
21
OnInit ,
@@ -25,7 +26,7 @@ import {
25
26
ViewEncapsulation
26
27
} from '@angular/core' ;
27
28
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
28
- import { Subject } from 'rxjs' ;
29
+ import { fromEvent , Subject } from 'rxjs' ;
29
30
import { takeUntil } from 'rxjs/operators' ;
30
31
31
32
import { BooleanInput , NzSizeLDSType , OnChangeType , OnTouchedType } from 'ng-zorro-antd/core/types' ;
@@ -70,8 +71,6 @@ import { InputBoolean, isNotNil } from 'ng-zorro-antd/core/util';
70
71
[placeholder]="nzPlaceHolder"
71
72
[attr.step]="nzStep"
72
73
[attr.inputmode]="nzInputMode"
73
- (keydown)="onKeyDown($event)"
74
- (keyup)="stop()"
75
74
[ngModel]="displayValue"
76
75
(ngModelChange)="onModelChange($event)"
77
76
/>
@@ -336,20 +335,6 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn
336
335
this . inputElement . nativeElement . value = `${ displayValue } ` ;
337
336
}
338
337
339
- onKeyDown ( e : KeyboardEvent ) : void {
340
- if ( e . keyCode === UP_ARROW ) {
341
- const ratio = this . getRatio ( e ) ;
342
- this . up ( e , ratio ) ;
343
- this . stop ( ) ;
344
- } else if ( e . keyCode === DOWN_ARROW ) {
345
- const ratio = this . getRatio ( e ) ;
346
- this . down ( e , ratio ) ;
347
- this . stop ( ) ;
348
- } else if ( e . keyCode === ENTER ) {
349
- this . updateDisplayValue ( this . value ! ) ;
350
- }
351
- }
352
-
353
338
writeValue ( value : number ) : void {
354
339
this . value = value ;
355
340
this . setValue ( value ) ;
@@ -379,7 +364,8 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn
379
364
}
380
365
381
366
constructor (
382
- private elementRef : ElementRef ,
367
+ private ngZone : NgZone ,
368
+ private elementRef : ElementRef < HTMLElement > ,
383
369
private cdr : ChangeDetectorRef ,
384
370
private focusMonitor : FocusMonitor ,
385
371
@Optional ( ) private directionality : Directionality
@@ -402,9 +388,41 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn
402
388
} ) ;
403
389
404
390
this . dir = this . directionality . value ;
405
- this . directionality . change ? .pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( direction : Direction ) => {
391
+ this . directionality . change . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( direction : Direction ) => {
406
392
this . dir = direction ;
407
393
} ) ;
394
+
395
+ this . ngZone . runOutsideAngular ( ( ) => {
396
+ fromEvent ( this . inputElement . nativeElement , 'keyup' )
397
+ . pipe ( takeUntil ( this . destroy$ ) )
398
+ . subscribe ( ( ) => this . stop ( ) ) ;
399
+
400
+ fromEvent < KeyboardEvent > ( this . inputElement . nativeElement , 'keydown' )
401
+ . pipe ( takeUntil ( this . destroy$ ) )
402
+ . subscribe ( event => {
403
+ const { keyCode } = event ;
404
+
405
+ if ( keyCode !== UP_ARROW && keyCode !== DOWN_ARROW && keyCode !== ENTER ) {
406
+ return ;
407
+ }
408
+
409
+ this . ngZone . run ( ( ) => {
410
+ if ( keyCode === UP_ARROW ) {
411
+ const ratio = this . getRatio ( event ) ;
412
+ this . up ( event , ratio ) ;
413
+ this . stop ( ) ;
414
+ } else if ( keyCode === DOWN_ARROW ) {
415
+ const ratio = this . getRatio ( event ) ;
416
+ this . down ( event , ratio ) ;
417
+ this . stop ( ) ;
418
+ } else {
419
+ this . updateDisplayValue ( this . value ! ) ;
420
+ }
421
+
422
+ this . cdr . markForCheck ( ) ;
423
+ } ) ;
424
+ } ) ;
425
+ } ) ;
408
426
}
409
427
410
428
ngOnChanges ( changes : SimpleChanges ) : void {
0 commit comments