Skip to content

Commit

Permalink
fix(select): active item not being updated on click in multiple mode (#…
Browse files Browse the repository at this point in the history
…7808)

Fixes the active option not being updated when the user clicks inside a multi-select, causing it to be stuck on the first option.
  • Loading branch information
crisbeto authored and jelbourn committed Jan 8, 2018
1 parent b71d954 commit ce2487e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3418,6 +3418,22 @@ describe('MatSelect', () => {
'Expected `multiple` to have been set on dynamically-added option.');
}));

it('should update the active item index on click', fakeAsync(() => {
trigger.click();
fixture.detectChanges();
flush();

expect(fixture.componentInstance.select._keyManager.activeItemIndex).toBe(0);

const options = overlayContainerElement.querySelectorAll('mat-option') as
NodeListOf<HTMLElement>;

options[2].click();
fixture.detectChanges();

expect(fixture.componentInstance.select._keyManager.activeItemIndex).toBe(2);
}));

});
});

Expand Down
1 change: 1 addition & 0 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
this._selectionModel.toggle(option);
this.stateChanges.next();
wasSelected ? option.deselect() : option.select();
this._keyManager.setActiveItem(this._getOptionIndex(option)!);
this._sortValues();
} else {
this._clearSelection(option.value == null ? undefined : option);
Expand Down

0 comments on commit ce2487e

Please sign in to comment.