Skip to content

Commit cfe3e98

Browse files
karajelbourn
authored andcommitted
fix(menu): properly handle spacebar events (#1533)
Closes #1175
1 parent 0b54668 commit cfe3e98

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

e2e/components/menu/menu.e2e.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,16 @@ describe('menu', () => {
7373
page.pressKey(protractor.Key.TAB);
7474
});
7575

76-
it('should auto-focus the first item when opened with keyboard', () => {
76+
it('should auto-focus the first item when opened with ENTER', () => {
7777
page.pressKey(protractor.Key.ENTER);
7878
page.expectFocusOn(page.items(0));
7979
});
8080

81+
it('should auto-focus the first item when opened with SPACE', () => {
82+
page.pressKey(protractor.Key.SPACE);
83+
page.expectFocusOn(page.items(0));
84+
});
85+
8186
it('should not focus the first item when opened with mouse', () => {
8287
page.trigger().click();
8388
page.expectFocusOn(page.trigger());

src/lib/core/keyboard/keycodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export const RIGHT_ARROW = 39;
1010
export const LEFT_ARROW = 37;
1111

1212
export const ENTER = 13;
13+
export const SPACE = 32;
1314
export const TAB = 9;

src/lib/menu/menu-trigger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {MdMenu} from './menu-directive';
1414
import {MdMenuMissingError} from './menu-errors';
1515
import {
1616
ENTER,
17+
SPACE,
1718
Overlay,
1819
OverlayState,
1920
OverlayRef,
@@ -172,7 +173,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
172173

173174
// TODO: internal
174175
_handleKeydown(event: KeyboardEvent): void {
175-
if (event.keyCode === ENTER) {
176+
if (event.keyCode === ENTER || event.keyCode === SPACE) {
176177
this._openedFromKeyboard = true;
177178
}
178179
}

0 commit comments

Comments
 (0)