Skip to content

Commit

Permalink
fix(menu): properly handle spacebar events (#1533)
Browse files Browse the repository at this point in the history
Closes #1175
  • Loading branch information
kara authored and jelbourn committed Oct 19, 2016
1 parent 0b54668 commit cfe3e98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion e2e/components/menu/menu.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/keyboard/keycodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {MdMenu} from './menu-directive';
import {MdMenuMissingError} from './menu-errors';
import {
ENTER,
SPACE,
Overlay,
OverlayState,
OverlayRef,
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit cfe3e98

Please sign in to comment.