fix(select): page scrolling down when selecting option with space (#5192)

Fixes the page being scrolled down if the user presses space to select an option. This is a regression since it used to be handled by the `ListKeyManager`, but it got lost when it was refactored not to disable the default actions.
This commit is contained in:
Kristiyan Kostadinov
2017-06-23 21:58:35 +02:00
committed by Jeremy Elbourn
parent fc809ede4b
commit 2361385dfc
2 changed files with 23 additions and 0 deletions
+3
View File
@@ -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();
}
}
+20
View File
@@ -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', () => {