Commit aee0c717 authored by scottchen's avatar scottchen Committed by Commit bot

WebUI: fix cr-action-menu keyboard off-by-one issue

BUG=None
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2803543003
Cr-Commit-Position: refs/heads/master@{#462732}
parent 15f5b51d
......@@ -40,6 +40,10 @@ suite('CrActionMenu', function() {
MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown');
}
function up() {
MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
}
test('hidden or disabled items', function() {
menu.showAt(document.querySelector('#dots'));
down();
......@@ -59,10 +63,6 @@ suite('CrActionMenu', function() {
});
test('focus after down/up arrow', function() {
function up() {
MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
}
menu.showAt(document.querySelector('#dots'));
// The menu should be focused when shown, but not on any of the items.
......@@ -93,6 +93,14 @@ suite('CrActionMenu', function() {
assertEquals(items[0], menu.root.activeElement);
});
test('pressing up arrow when no focus will focus last item', function(){
menu.showAt(document.querySelector('#dots'));
assertEquals(menu, document.activeElement);
up();
assertEquals(items[items.length - 1], menu.root.activeElement);
});
test('close on resize', function() {
menu.showAt(document.querySelector('#dots'));
assertTrue(menu.open);
......
......@@ -131,6 +131,10 @@ Polymer({
var focusedIndex =
Array.prototype.indexOf.call(this.options_, this.root.activeElement);
// Handle case where nothing is focused and up is pressed.
if (focusedIndex === -1 && step === -1)
focusedIndex = 0;
do {
focusedIndex = (numOptions + focusedIndex + step) % numOptions;
nextOption = this.options_[focusedIndex];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment