Chromium Code Reviews| 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 9f58dc4f6cd9079f59c2ee05364b0f1f5aef5e46..1db658c94145dd1b8139b106e457e659cf9125c9 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 |
| @@ -32,6 +32,7 @@ Polymer({ |
| listeners: { |
| 'keydown': 'onKeyDown_', |
| + 'mouseover': 'onMouseover_', |
| 'tap': 'onTap_', |
| }, |
| @@ -73,6 +74,8 @@ Polymer({ |
| return; |
| } |
| + listenOnce(this, 'mousemove', this.onMouseover_.bind(this)); |
|
dpapad
2017/04/06 00:06:02
We are leaking mousemove listeners. When the user
Dan Beam
2017/04/06 00:08:35
sure, that makes sense
scottchen
2017/04/06 00:44:33
Done.
|
| + |
| if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') |
| return; |
| @@ -84,6 +87,25 @@ Polymer({ |
| }, |
| /** |
| + * @param {!MouseEvent} e |
| + * @private |
| + */ |
| + onMouseover_: function(e) { |
| + // TODO(scottchen): Using "focus" to determine selected item might mess |
| + // with screen readers in some edge cases. |
| + var target = e.path[0]; |
| + for (var i = 0; this != target; target = e.path[i++]) { |
|
Dan Beam
2017/04/05 23:42:30
nit:
var i = 0;
for (var target; this != target;
scottchen
2017/04/06 00:44:33
I changed it to a do-while for readability.
|
| + if (target.classList && target.classList.contains('dropdown-item')) { |
| + target.focus(); |
| + return; |
| + } |
| + }; |
| + |
| + // The user moved the mouse off the options. Reset focus to the dialog. |
| + this.focus(); |
| + }, |
| + |
| + /** |
| * @param {number} step -1 for getting previous option (up), 1 for getting |
| * next option (down). |
| * @return {?Element} The next focusable option, taking into account |