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
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