33 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44 */
55
6+ import { FocusMonitor } from '@angular/cdk/a11y' ;
67import { Direction , Directionality } from '@angular/cdk/bidi' ;
78import {
89 ComponentRef ,
@@ -43,7 +44,8 @@ import { NZ_SPACE_COMPACT_ITEM_TYPE, NZ_SPACE_COMPACT_SIZE, NzSpaceCompactItemDi
4344 '[class.ant-input-sm]' : `finalSize() === 'small'` ,
4445 '[attr.disabled]' : 'disabled || null' ,
4546 '[class.ant-input-rtl]' : `dir=== 'rtl'` ,
46- '[class.ant-input-stepperless]' : `nzStepperless`
47+ '[class.ant-input-stepperless]' : `nzStepperless` ,
48+ '[class.ant-input-focused]' : 'focused()'
4749 } ,
4850 hostDirectives : [ NzSpaceCompactItemDirective ] ,
4951 providers : [ { provide : NZ_SPACE_COMPACT_ITEM_TYPE , useValue : 'input' } ]
@@ -57,6 +59,7 @@ export class NzInputDirective implements OnChanges, OnInit {
5759 private destroyRef = inject ( DestroyRef ) ;
5860 private nzFormStatusService = inject ( NzFormStatusService , { optional : true } ) ;
5961 private nzFormNoStatusService = inject ( NzFormNoStatusService , { optional : true } ) ;
62+ private focusMonitor = inject ( FocusMonitor ) ;
6063
6164 /**
6265 * @deprecated Will be removed in v21. It is recommended to use `nzVariant` instead.
@@ -89,6 +92,7 @@ export class NzInputDirective implements OnChanges, OnInit {
8992 components : Array < ComponentRef < NzFormItemFeedbackIconComponent > > = [ ] ;
9093 ngControl = inject ( NgControl , { self : true , optional : true } ) ;
9194
95+ protected focused = signal < boolean > ( false ) ;
9296 protected finalSize = computed ( ( ) => {
9397 if ( this . compactSize ) {
9498 return this . compactSize ( ) ;
@@ -98,6 +102,12 @@ export class NzInputDirective implements OnChanges, OnInit {
98102
99103 private size = signal < NzSizeLDSType > ( this . nzSize ) ;
100104
105+ constructor ( ) {
106+ this . destroyRef . onDestroy ( ( ) => {
107+ this . focusMonitor . stopMonitoring ( this . elementRef ) ;
108+ } ) ;
109+ }
110+
101111 ngOnInit ( ) : void {
102112 this . nzFormStatusService ?. formStatusChanges
103113 . pipe (
@@ -125,6 +135,11 @@ export class NzInputDirective implements OnChanges, OnInit {
125135 this . directionality . change ?. pipe ( takeUntilDestroyed ( this . destroyRef ) ) . subscribe ( ( direction : Direction ) => {
126136 this . dir = direction ;
127137 } ) ;
138+
139+ this . focusMonitor
140+ . monitor ( this . elementRef , false )
141+ . pipe ( takeUntilDestroyed ( this . destroyRef ) )
142+ . subscribe ( origin => this . focused . set ( ! ! origin ) ) ;
128143 }
129144
130145 ngOnChanges ( { disabled, nzStatus, nzSize } : SimpleChanges ) : void {
0 commit comments