From 3dcdb6d89703c0826894c751528de10c356bde6a Mon Sep 17 00:00:00 2001 From: Steven Xu Date: Thu, 14 Mar 2019 16:01:04 -0700 Subject: [PATCH] fix(form-field): remove nonbreaking space before * for required fields The surrounding .mat-form-field-label is already white-space: nowrap so the   doesn't serve any wrap-preventing function. But it does prevent any trailing spacing from collapsing with the space before the asterisk, causing for a bad visual appearance of a double space in these cases. --- src/lib/form-field/form-field.html | 2 +- src/lib/input/input.spec.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/form-field/form-field.html b/src/lib/form-field/form-field.html index e6c91f58a9e6..133b42f98ae8 100644 --- a/src/lib/form-field/form-field.html +++ b/src/lib/form-field/form-field.html @@ -52,7 +52,7 @@ + *ngIf="!hideRequiredMarker && _control.required && !_control.disabled"> * diff --git a/src/lib/input/input.spec.ts b/src/lib/input/input.spec.ts index 96121aaae9aa..6e802befb65c 100644 --- a/src/lib/input/input.spec.ts +++ b/src/lib/input/input.spec.ts @@ -394,7 +394,7 @@ describe('MatInput without forms', () => { let el = fixture.debugElement.query(By.css('label')); expect(el).not.toBeNull(); - expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g); + expect(el.nativeElement.textContent).toMatch(/hello +\*/g); })); it('should hide the required star if input is disabled', () => { @@ -407,6 +407,7 @@ describe('MatInput without forms', () => { expect(el).not.toBeNull(); expect(el.nativeElement.textContent!.trim()).toMatch(/^hello$/); + expect(el.nativeElement.textContent).not.toMatch(/\*/g); }); it('should hide the required star from screen readers', fakeAsync(() => { @@ -424,12 +425,13 @@ describe('MatInput without forms', () => { let el = fixture.debugElement.query(By.css('label')); expect(el).not.toBeNull(); - expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g); + expect(el.nativeElement.textContent).toMatch(/hello +\*/g); fixture.componentInstance.hideRequiredMarker = true; fixture.detectChanges(); expect(el.nativeElement.textContent).toMatch(/hello/g); + expect(el.nativeElement.textContent).not.toMatch(/\*/g); })); it('supports the disabled attribute as binding', fakeAsync(() => {