mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Seguin
parent
0c4ee2efa4
commit
1c2f6b7cbe
@@ -41,7 +41,7 @@
|
||||
<span
|
||||
class="mat-placeholder-required mat-form-field-required-marker"
|
||||
aria-hidden="true"
|
||||
*ngIf="!hideRequiredMarker && _control.required"> *</span>
|
||||
*ngIf="!hideRequiredMarker && _control.required && !_control.disabled"> *</span>
|
||||
</label>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user