fix(form-field): hide required asterisk if control is disabled (#8799)

* No longer shows the required asterisk if the form control is disabled.

Fixes #8251.
This commit is contained in:
Paul Gschwendtner
2018-01-12 16:06:49 +01:00
committed by Andrew Seguin
parent 0c4ee2efa4
commit 1c2f6b7cbe
2 changed files with 16 additions and 3 deletions
+1 -1
View File
@@ -41,7 +41,7 @@
<span
class="mat-placeholder-required mat-form-field-required-marker"
aria-hidden="true"
*ngIf="!hideRequiredMarker && _control.required">&nbsp;*</span>
*ngIf="!hideRequiredMarker && _control.required && !_control.disabled">&nbsp;*</span>
</label>
</span>
</div>
+15 -2
View File
@@ -413,6 +413,18 @@ describe('MatInput without forms', () => {
expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g);
}));
it('should hide the required star if input is disabled', () => {
const fixture = TestBed.createComponent(MatInputPlaceholderRequiredTestComponent);
fixture.componentInstance.disabled = true;
fixture.detectChanges();
const el = fixture.debugElement.query(By.css('label'));
expect(el).not.toBeNull();
expect(el.nativeElement.textContent).toMatch(/^hello$/);
});
it('should hide the required star from screen readers', fakeAsync(() => {
let fixture = TestBed.createComponent(MatInputPlaceholderRequiredTestComponent);
fixture.detectChanges();
@@ -1151,11 +1163,12 @@ class MatInputWithType {
@Component({
template: `<mat-form-field [hideRequiredMarker]="hideRequiredMarker">
<input matInput required placeholder="hello">
<input matInput required [disabled]="disabled" placeholder="hello">
</mat-form-field>`
})
class MatInputPlaceholderRequiredTestComponent {
hideRequiredMarker: boolean;
hideRequiredMarker: boolean = false;
disabled: boolean = false;
}
@Component({