Skip to content

Commit 68be665

Browse files
authored
fix(module:input): style filled variant (#9262)
1 parent eb9e927 commit 68be665

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

components/input/input.directive.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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';
67
import { Direction, Directionality } from '@angular/cdk/bidi';
78
import {
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 {

components/input/style/mixin.less

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@
9898
box-shadow: none !important;
9999
}
100100

101-
&-filled& {
101+
&-filled {
102102
background-color: @input-variant-filled-bg !important;
103-
border-color: transparent !important;
103+
border-color: transparent;
104104
box-shadow: none !important;
105105
}
106106

107-
&-filled:hover {
107+
&-filled:hover&:not(&-focused) {
108108
background-color: @input-variant-filled-hover-bg !important;
109109
border-color: transparent !important;
110110
}

0 commit comments

Comments
 (0)