Skip to content

Commit c111d92

Browse files
committed
fix(select): active item not being updated on click in multiple mode
Fixes the active option not being updated when the user clicks inside a multi-select, causing it to be stuck on the first option.
1 parent 9673f63 commit c111d92

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/lib/select/select.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,22 @@ describe('MatSelect', () => {
28592859
});
28602860
}));
28612861

2862+
it('should update the active item index on click', fakeAsync(() => {
2863+
trigger.click();
2864+
fixture.detectChanges();
2865+
tick(SELECT_OPEN_ANIMATION);
2866+
2867+
expect(fixture.componentInstance.select._keyManager.activeItemIndex).toBe(0);
2868+
2869+
const options = overlayContainerElement.querySelectorAll('mat-option') as
2870+
NodeListOf<HTMLElement>;
2871+
2872+
options[2].click();
2873+
fixture.detectChanges();
2874+
2875+
expect(fixture.componentInstance.select._keyManager.activeItemIndex).toBe(2);
2876+
}));
2877+
28622878
});
28632879

28642880
describe('theming', () => {

src/lib/select/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
817817
this._selectionModel.toggle(option);
818818
this.stateChanges.next();
819819
wasSelected ? option.deselect() : option.select();
820+
this._keyManager.setActiveItem(this._getOptionIndex(option)!);
820821
this._sortValues();
821822
} else {
822823
this._clearSelection(option.value == null ? undefined : option);

0 commit comments

Comments
 (0)