fix(chips): form field not appearing as blurred when used without an input (#12858)

Fixes blurring a chip list within a form field, without an input, not reflecting its state in the UI.
This commit is contained in:
Kristiyan Kostadinov
2018-08-28 16:57:11 +02:00
committed by Jeremy Elbourn
parent d424c70676
commit f82a94bd51
2 changed files with 22 additions and 3 deletions
+16
View File
@@ -772,6 +772,22 @@ describe('MatChipList', () => {
expect(chipArray[4].focus).not.toHaveBeenCalled();
});
it('should blur the form field when the active chip is blurred', fakeAsync(() => {
const formField: HTMLElement = fixture.nativeElement.querySelector('.mat-form-field');
nativeChips[0].focus();
fixture.detectChanges();
expect(formField.classList).toContain('mat-focused');
nativeChips[0].blur();
fixture.detectChanges();
zone.simulateZoneExit();
fixture.detectChanges();
expect(formField.classList).not.toContain('mat-focused');
}));
});
describe('multiple selection', () => {
+6 -3
View File
@@ -367,9 +367,12 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
this._ngZone.onStable
.asObservable()
.pipe(take(1))
.subscribe(() => this._hasFocus = false);
this._onBlur.next({chip: this});
.subscribe(() => {
this._ngZone.run(() => {
this._hasFocus = false;
this._onBlur.next({chip: this});
});
});
}
}