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-04 06:40:41 +00:00
parent 7cb98a969e
commit 992c414ee4
4 changed files with 38 additions and 23 deletions
@@ -318,18 +318,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;
}
@@ -337,11 +341,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.
@@ -349,13 +353,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);
}
}
}
@@ -404,7 +409,7 @@ ACTIONMENU.prototype = {
if (next) {
next.focus();
e.preventDefault();
markEventHandled(e);
}
}
},
File diff suppressed because one or more lines are too long
@@ -316,18 +316,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;
}
@@ -335,11 +339,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.
@@ -347,13 +351,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);
}
}
},
+12 -7
View File
@@ -316,18 +316,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;
}
@@ -335,11 +339,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.
@@ -347,13 +351,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);
}
}
}
@@ -402,7 +407,7 @@ ACTIONMENU.prototype = {
if (next) {
next.focus();
e.preventDefault();
markEventHandled(e);
}
}
},