Skip to content

Commit f82a94b

Browse files
crisbetojelbourn
authored andcommitted
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.
1 parent d424c70 commit f82a94b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/lib/chips/chip-list.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,22 @@ describe('MatChipList', () => {
772772

773773
expect(chipArray[4].focus).not.toHaveBeenCalled();
774774
});
775+
776+
it('should blur the form field when the active chip is blurred', fakeAsync(() => {
777+
const formField: HTMLElement = fixture.nativeElement.querySelector('.mat-form-field');
778+
779+
nativeChips[0].focus();
780+
fixture.detectChanges();
781+
782+
expect(formField.classList).toContain('mat-focused');
783+
784+
nativeChips[0].blur();
785+
fixture.detectChanges();
786+
zone.simulateZoneExit();
787+
fixture.detectChanges();
788+
789+
expect(formField.classList).not.toContain('mat-focused');
790+
}));
775791
});
776792

777793
describe('multiple selection', () => {

src/lib/chips/chip.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,12 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
367367
this._ngZone.onStable
368368
.asObservable()
369369
.pipe(take(1))
370-
.subscribe(() => this._hasFocus = false);
371-
372-
this._onBlur.next({chip: this});
370+
.subscribe(() => {
371+
this._ngZone.run(() => {
372+
this._hasFocus = false;
373+
this._onBlur.next({chip: this});
374+
});
375+
});
373376
}
374377
}
375378

0 commit comments

Comments
 (0)