File tree 2 files changed +16
-3
lines changed
2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 41
41
< span
42
42
class ="mat-placeholder-required mat-form-field-required-marker "
43
43
aria-hidden ="true "
44
- *ngIf ="!hideRequiredMarker && _control.required "> *</ span >
44
+ *ngIf ="!hideRequiredMarker && _control.required && !_control.disabled "> *</ span >
45
45
</ label >
46
46
</ span >
47
47
</ div >
Original file line number Diff line number Diff line change @@ -413,6 +413,18 @@ describe('MatInput without forms', () => {
413
413
expect ( el . nativeElement . textContent ) . toMatch ( / h e l l o \s + \* / g) ;
414
414
} ) ) ;
415
415
416
+ it ( 'should hide the required star if input is disabled' , ( ) => {
417
+ const fixture = TestBed . createComponent ( MatInputPlaceholderRequiredTestComponent ) ;
418
+
419
+ fixture . componentInstance . disabled = true ;
420
+ fixture . detectChanges ( ) ;
421
+
422
+ const el = fixture . debugElement . query ( By . css ( 'label' ) ) ;
423
+
424
+ expect ( el ) . not . toBeNull ( ) ;
425
+ expect ( el . nativeElement . textContent ) . toMatch ( / ^ h e l l o $ / ) ;
426
+ } ) ;
427
+
416
428
it ( 'should hide the required star from screen readers' , fakeAsync ( ( ) => {
417
429
let fixture = TestBed . createComponent ( MatInputPlaceholderRequiredTestComponent ) ;
418
430
fixture . detectChanges ( ) ;
@@ -1151,11 +1163,12 @@ class MatInputWithType {
1151
1163
1152
1164
@Component ( {
1153
1165
template : `<mat-form-field [hideRequiredMarker]="hideRequiredMarker">
1154
- <input matInput required placeholder="hello">
1166
+ <input matInput required [disabled]="disabled" placeholder="hello">
1155
1167
</mat-form-field>`
1156
1168
} )
1157
1169
class MatInputPlaceholderRequiredTestComponent {
1158
- hideRequiredMarker : boolean ;
1170
+ hideRequiredMarker : boolean = false ;
1171
+ disabled : boolean = false ;
1159
1172
}
1160
1173
1161
1174
@Component ( {
You can’t perform that action at this time.
0 commit comments