mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Jeremy Elbourn
parent
fc809ede4b
commit
2361385dfc
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user