Skip to content
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
3 changes: 3 additions & 0 deletions src/lib/core/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export class MdOption {
_handleKeydown(event: KeyboardEvent): void {
if (event.keyCode === ENTER || event.keyCode === SPACE) {
this._selectViaInteraction();

// Prevent the page from scrolling down and form submits.
event.preventDefault();
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,26 @@ describe('MdSelect', () => {
expect(panel.classList).toContain('custom-two');
});

it('should prevent the default action when pressing SPACE on an option', () => {
trigger.click();
fixture.detectChanges();

const option = overlayContainerElement.querySelector('md-option');
const event = dispatchKeyboardEvent(option, 'keydown', SPACE);

expect(event.defaultPrevented).toBe(true);
});

it('should prevent the default action when pressing ENTER on an option', () => {
trigger.click();
fixture.detectChanges();

const option = overlayContainerElement.querySelector('md-option');
const event = dispatchKeyboardEvent(option, 'keydown', ENTER);

expect(event.defaultPrevented).toBe(true);
});

});

describe('selection logic', () => {
Expand Down