Skip to content

Commit ef4e9ea

Browse files
committed
fix(material/input): fix input suffix disabled color
1 parent fdb30ad commit ef4e9ea

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/material/form-field/directives/suffix.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ export const MAT_SUFFIX = new InjectionToken<MatSuffix>('MatSuffix');
2323
export class MatSuffix {
2424
_isText = false;
2525

26-
constructor(elementRef: ElementRef) {
26+
constructor(private elementRef: ElementRef<HTMLElement>) {
2727
this._isText = elementRef.nativeElement.hasAttribute('matTextSuffix');
2828
}
29+
30+
disable(): void {
31+
this.elementRef.nativeElement.classList.add('mat-form-field-suffix--disabled');
32+
}
33+
34+
enable(): void {
35+
this.elementRef.nativeElement.classList.remove('mat-form-field-suffix--disabled');
36+
}
2937
}

src/material/input/input.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ export class MatInput
167167
}
168168
set disabled(value: BooleanInput) {
169169
this._disabled = coerceBooleanProperty(value);
170+
this._formField?._suffixChildren?.forEach(suffix =>
171+
this._disabled ? suffix.disable() : suffix.enable(),
172+
);
170173

171174
// Browsers may not fire the blur event if the input is disabled too quickly.
172175
// Reset from here to ensure that the element doesn't become stuck.
@@ -332,6 +335,12 @@ export class MatInput
332335
this.stateChanges.next();
333336
});
334337
}
338+
339+
if (this._disabled) {
340+
this._formField?._suffixChildren.forEach(suffix => {
341+
suffix.disable();
342+
});
343+
}
335344
}
336345

337346
ngOnChanges() {

src/material/legacy-form-field/suffix.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Directive} from '@angular/core';
9+
import {Directive, ElementRef} from '@angular/core';
1010
import {MAT_SUFFIX} from '@angular/material/form-field';
1111

1212
/** Suffix to be placed at the end of the form field. */
1313
@Directive({
1414
selector: '[matSuffix]',
1515
providers: [{provide: MAT_SUFFIX, useExisting: MatLegacySuffix}],
1616
})
17-
export class MatLegacySuffix {}
17+
export class MatLegacySuffix {
18+
constructor(private elementRef: ElementRef<HTMLElement>) {}
19+
20+
disable(): void {
21+
this.elementRef.nativeElement.classList.add('mat-form-field-suffix--disabled');
22+
}
23+
24+
enable(): void {
25+
this.elementRef.nativeElement.classList.remove('mat-form-field-suffix--disabled');
26+
}
27+
}

src/material/legacy-input/_input-theme.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
caret-color: theming.get-color-from-palette($accent, text);
5454
}
5555

56+
.mat-form-field-suffix--disabled {
57+
color: theming.get-color-from-palette($foreground, disabled-text);
58+
}
59+
5660
.mat-form-field.mat-warn .mat-input-element,
5761
.mat-form-field-invalid .mat-input-element {
5862
caret-color: theming.get-color-from-palette($warn, text);

0 commit comments

Comments
 (0)