Skip to content

fix(select): not resuming keyboard selection after clicking on single-select option #11882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,28 @@ describe('MatSelect', () => {
'Expected value from second option to have been set on the model.');
}));

it('should resume focus from selected item after selecting via click', fakeAsync(() => {
const formControl = fixture.componentInstance.control;
const options = fixture.componentInstance.options.toArray();

expect(formControl.value).toBeFalsy('Expected no initial value.');

fixture.componentInstance.select.open();
fixture.detectChanges();
flush();

(overlayContainerElement.querySelectorAll('mat-option')[3] as HTMLElement).click();
fixture.detectChanges();
flush();

expect(formControl.value).toBe(options[3].value);

dispatchKeyboardEvent(select, 'keydown', DOWN_ARROW);
fixture.detectChanges();

expect(formControl.value).toBe(options[4].value);
}));

it('should select options via LEFT/RIGHT arrow keys on a closed select', fakeAsync(() => {
const formControl = fixture.componentInstance.control;
const options = fixture.componentInstance.options.toArray();
Expand Down
6 changes: 4 additions & 2 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,14 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
} else {
option.selected ? this._selectionModel.select(option) : this._selectionModel.deselect(option);

if (isUserInput) {
this._keyManager.setActiveItem(option);
}

if (this.multiple) {
this._sortValues();

if (isUserInput) {
this._keyManager.setActiveItem(option);

// In case the user selected the option with their mouse, we
// want to restore focus back to the trigger, in order to
// prevent the select keyboard controls from clashing with
Expand Down