Skip to content

Commit 5a8a01f

Browse files
committed
update wrap fn
1 parent 28dbf51 commit 5a8a01f

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/lib/menu/menu-directive.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ export class MdMenu {
100100
this.close.emit(null);
101101
}
102102

103-
// When focus would shift past the start or end of the menu, wrap back to the beginning or end
104-
private _wrapIfFocusLeavesMenu(): void {
105-
if (this._focusedItemIndex >= this.items.length) {
106-
this._focusedItemIndex = 0;
107-
} else if (this._focusedItemIndex < 0) {
108-
this._focusedItemIndex = this.items.length - 1;
109-
}
110-
}
111-
112103
private _focusNextItem(): void {
113104
this._updateFocusedItemIndex(1);
114105
this.items.toArray()[this._focusedItemIndex].focus();
@@ -130,8 +121,9 @@ export class MdMenu {
130121
* @private
131122
*/
132123
private _updateFocusedItemIndex(delta: number, menuItems: MdMenuItem[] = this.items.toArray()) {
133-
this._focusedItemIndex += delta;
134-
this._wrapIfFocusLeavesMenu();
124+
// when focus would leave menu, wrap to beginning or end
125+
this._focusedItemIndex = (this._focusedItemIndex + delta + this.items.length)
126+
% this.items.length;
135127

136128
// skip all disabled menu items recursively until an active one
137129
// is reached or the menu closes for overreaching bounds

0 commit comments

Comments
 (0)