From cd32d7885452da1508b376babd7b6370c278c48a Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 26 Jun 2018 21:47:07 +0200 Subject: [PATCH] fix(select): reset option being marked as selected (#11934) --- src/lib/select/select.spec.ts | 12 ++++++++++++ src/lib/select/select.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index cac35e08f50d..3b7432bc5e15 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -2580,6 +2580,18 @@ describe('MatSelect', () => { expect(trigger.textContent).not.toContain('None'); })); + it('should not mark the reset option as selected ', fakeAsync(() => { + options[5].click(); + fixture.detectChanges(); + flush(); + + fixture.componentInstance.select.open(); + fixture.detectChanges(); + flush(); + + expect(options[5].classList).not.toContain('mat-selected'); + })); + it('should not reset when any other falsy option is selected', fakeAsync(() => { options[3].click(); fixture.detectChanges(); diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 9172df03dd12..b5468157e5a0 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -881,6 +881,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, const wasSelected = this._selectionModel.isSelected(option); if (option.value == null && !this._multiple) { + option.deselect(); this._selectionModel.clear(); this._propagateChanges(option.value); } else {