fix(menu): properly handle spacebar events (#1533)

Closes #1175
This commit is contained in:
Kara
2016-10-19 15:36:54 -07:00
committed by Jeremy Elbourn
parent 0b54668b4d
commit cfe3e981bd
3 changed files with 9 additions and 2 deletions
+6 -1
View File
@@ -73,11 +73,16 @@ describe('menu', () => {
page.pressKey(protractor.Key.TAB);
});
it('should auto-focus the first item when opened with keyboard', () => {
it('should auto-focus the first item when opened with ENTER', () => {
page.pressKey(protractor.Key.ENTER);
page.expectFocusOn(page.items(0));
});
it('should auto-focus the first item when opened with SPACE', () => {
page.pressKey(protractor.Key.SPACE);
page.expectFocusOn(page.items(0));
});
it('should not focus the first item when opened with mouse', () => {
page.trigger().click();
page.expectFocusOn(page.trigger());
+1
View File
@@ -10,4 +10,5 @@ export const RIGHT_ARROW = 39;
export const LEFT_ARROW = 37;
export const ENTER = 13;
export const SPACE = 32;
export const TAB = 9;
+2 -1
View File
@@ -14,6 +14,7 @@ import {MdMenu} from './menu-directive';
import {MdMenuMissingError} from './menu-errors';
import {
ENTER,
SPACE,
Overlay,
OverlayState,
OverlayRef,
@@ -172,7 +173,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
// TODO: internal
_handleKeydown(event: KeyboardEvent): void {
if (event.keyCode === ENTER) {
if (event.keyCode === ENTER || event.keyCode === SPACE) {
this._openedFromKeyboard = true;
}
}