Skip to content
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

fix(select): alt + arrow key not opening in single-selection mode #8910

Merged
merged 1 commit into from
Dec 13, 2017
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
30 changes: 30 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,36 @@ describe('MatSelect', () => {
'Expected value from second option to have been set on the model.');
}));

it('should open a single-selection select using ALT + DOWN_ARROW', fakeAsync(() => {
const {control: formControl, select: selectInstance} = fixture.componentInstance;

expect(selectInstance.panelOpen).toBe(false, 'Expected select to be closed.');
expect(formControl.value).toBeFalsy('Expected no initial value.');

const event = createKeyboardEvent('keydown', DOWN_ARROW);
Object.defineProperty(event, 'altKey', {get: () => true});

dispatchEvent(select, event);

expect(selectInstance.panelOpen).toBe(true, 'Expected select to be open.');
expect(formControl.value).toBeFalsy('Expected value not to have changed.');
}));

it('should open a single-selection select using ALT + UP_ARROW', fakeAsync(() => {
const {control: formControl, select: selectInstance} = fixture.componentInstance;

expect(selectInstance.panelOpen).toBe(false, 'Expected select to be closed.');
expect(formControl.value).toBeFalsy('Expected no initial value.');

const event = createKeyboardEvent('keydown', UP_ARROW);
Object.defineProperty(event, 'altKey', {get: () => true});

dispatchEvent(select, event);

expect(selectInstance.panelOpen).toBe(true, 'Expected select to be open.');
expect(formControl.value).toBeFalsy('Expected value not to have changed.');
}));

it('should be able to select options by typing on a closed select', fakeAsync(() => {
const formControl = fixture.componentInstance.control;
const options = fixture.componentInstance.options.toArray();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
const isArrowKey = keyCode === DOWN_ARROW || keyCode === UP_ARROW;
const isOpenKey = keyCode === ENTER || keyCode === SPACE;

if (isOpenKey || (this.multiple && isArrowKey)) {
if (isOpenKey || ((this.multiple || event.altKey) && isArrowKey)) {
event.preventDefault(); // prevents the page from scrolling down when pressing space
this.open();
} else if (!this.multiple) {
Expand Down