Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2280)

Unified Diff: ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js

Issue 2464873003: WebUI: Return focus to anchor element when cr-action-menu is closed. (Closed)
Patch Set: Resolve conflicts. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_action_menu_test.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
diff --git a/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js b/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
index 208b2aad658f1fdaccbe4f0a19433f4924385c42..51c87e5554bed1f9fc8ee816da312e70a81cc0dc 100644
--- a/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
+++ b/ui/webui/resources/cr_elements/cr_action_menu/cr_action_menu.js
@@ -13,6 +13,13 @@ Polymer({
options_: null,
/**
+ * The element which the action menu will be anchored to. Also the element
+ * where focus will be returned after the menu is closed.
+ * @private {?Element}
+ */
+ anchorElement_: null,
+
+ /**
* Reference to the bound window's resize listener, such that it can be
* removed on detach.
* @private {?Function}
@@ -59,8 +66,9 @@ Polymer({
* @private
*/
onKeyDown_: function(e) {
- if (e.key == 'Tab') {
+ if (e.key == 'Tab' || e.key == 'Escape') {
this.close();
+ e.preventDefault();
return;
}
@@ -106,6 +114,8 @@ Polymer({
// Removing 'resize' listener when dialog is closed.
this.removeResizeListener_();
HTMLDialogElement.prototype.close.call(this);
+ this.anchorElement_.focus();
+ this.anchorElement_ = null;
},
/**
@@ -113,6 +123,7 @@ Polymer({
* @param {!Element} anchorElement
*/
showAt: function(anchorElement) {
+ this.anchorElement_ = anchorElement;
this.onWindowResize_ = this.onWindowResize_ || function() {
if (this.open)
this.close();
@@ -121,8 +132,8 @@ Polymer({
this.showModal();
- var rect = anchorElement.getBoundingClientRect();
- if (getComputedStyle(anchorElement).direction == 'rtl') {
+ var rect = this.anchorElement_.getBoundingClientRect();
+ if (getComputedStyle(this.anchorElement_).direction == 'rtl') {
var right = window.innerWidth - rect.left - this.offsetWidth;
this.style.right = right + 'px';
} else {
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_action_menu_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698