MDL-51983 actionmenu: stop event propagation

Stop event propagation on keyboard events that have been
successfully handled by the action menu code.
This commit is contained in:
Ryan Wyllie 2015-11-03 05:29:55 +00:00
parent 4cef723c22
commit 4456c306df
4 changed files with 38 additions and 23 deletions

View File

@ -317,18 +317,22 @@ ACTIONMENU.prototype = {
*/
handleKeyboardEvent: function(e) {
var next;
var markEventHandled = function(e) {
e.preventDefault();
e.stopPropagation();
};
// Handle when the menu is still selected.
if (e.currentTarget.ancestor(SELECTOR.TOGGLE, true)) {
if ((e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) && this.firstMenuChild) {
this.firstMenuChild.focus();
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 38 && this.lastMenuChild) {
this.lastMenuChild.focus();
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 9 && e.shiftKey) {
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
}
return this;
}
@ -336,11 +340,11 @@ ACTIONMENU.prototype = {
if (e.keyCode === 27) {
// The escape key was pressed so close the menu.
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 32) {
// The space bar was pressed. Trigger a click.
e.preventDefault();
markEventHandled(e);
e.currentTarget.simulate('click');
} else if (e.keyCode === 9) {
// The tab key was pressed. Tab moves forwards, Shift + Tab moves backwards through the menu options.
@ -348,13 +352,14 @@ ACTIONMENU.prototype = {
// focus is moved to.
if (e.target === this.firstMenuChild && e.shiftKey) {
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
} else if (e.target === this.lastMenuChild && !e.shiftKey) {
if (this.hideMenu(e)) {
// Determine the next selector and focus on it.
next = this.menulink.next(SELECTOR.CAN_RECEIVE_FOCUS_SELECTOR);
if (next) {
next.focus();
markEventHandled(e);
}
}
}
@ -403,7 +408,7 @@ ACTIONMENU.prototype = {
if (next) {
next.focus();
e.preventDefault();
markEventHandled(e);
}
}
},

File diff suppressed because one or more lines are too long

View File

@ -315,18 +315,22 @@ ACTIONMENU.prototype = {
*/
handleKeyboardEvent: function(e) {
var next;
var markEventHandled = function(e) {
e.preventDefault();
e.stopPropagation();
};
// Handle when the menu is still selected.
if (e.currentTarget.ancestor(SELECTOR.TOGGLE, true)) {
if ((e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) && this.firstMenuChild) {
this.firstMenuChild.focus();
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 38 && this.lastMenuChild) {
this.lastMenuChild.focus();
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 9 && e.shiftKey) {
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
}
return this;
}
@ -334,11 +338,11 @@ ACTIONMENU.prototype = {
if (e.keyCode === 27) {
// The escape key was pressed so close the menu.
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 32) {
// The space bar was pressed. Trigger a click.
e.preventDefault();
markEventHandled(e);
e.currentTarget.simulate('click');
} else if (e.keyCode === 9) {
// The tab key was pressed. Tab moves forwards, Shift + Tab moves backwards through the menu options.
@ -346,13 +350,14 @@ ACTIONMENU.prototype = {
// focus is moved to.
if (e.target === this.firstMenuChild && e.shiftKey) {
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
} else if (e.target === this.lastMenuChild && !e.shiftKey) {
if (this.hideMenu(e)) {
// Determine the next selector and focus on it.
next = this.menulink.next(SELECTOR.CAN_RECEIVE_FOCUS_SELECTOR);
if (next) {
next.focus();
markEventHandled(e);
}
}
}
@ -400,7 +405,7 @@ ACTIONMENU.prototype = {
if (next) {
next.focus();
e.preventDefault();
markEventHandled(e);
}
}
},

View File

@ -315,18 +315,22 @@ ACTIONMENU.prototype = {
*/
handleKeyboardEvent: function(e) {
var next;
var markEventHandled = function(e) {
e.preventDefault();
e.stopPropagation();
};
// Handle when the menu is still selected.
if (e.currentTarget.ancestor(SELECTOR.TOGGLE, true)) {
if ((e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) && this.firstMenuChild) {
this.firstMenuChild.focus();
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 38 && this.lastMenuChild) {
this.lastMenuChild.focus();
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 9 && e.shiftKey) {
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
}
return this;
}
@ -334,11 +338,11 @@ ACTIONMENU.prototype = {
if (e.keyCode === 27) {
// The escape key was pressed so close the menu.
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
} else if (e.keyCode === 32) {
// The space bar was pressed. Trigger a click.
e.preventDefault();
markEventHandled(e);
e.currentTarget.simulate('click');
} else if (e.keyCode === 9) {
// The tab key was pressed. Tab moves forwards, Shift + Tab moves backwards through the menu options.
@ -346,13 +350,14 @@ ACTIONMENU.prototype = {
// focus is moved to.
if (e.target === this.firstMenuChild && e.shiftKey) {
this.hideMenu(e);
e.preventDefault();
markEventHandled(e);
} else if (e.target === this.lastMenuChild && !e.shiftKey) {
if (this.hideMenu(e)) {
// Determine the next selector and focus on it.
next = this.menulink.next(SELECTOR.CAN_RECEIVE_FOCUS_SELECTOR);
if (next) {
next.focus();
markEventHandled(e);
}
}
}
@ -401,7 +406,7 @@ ACTIONMENU.prototype = {
if (next) {
next.focus();
e.preventDefault();
markEventHandled(e);
}
}
},