Commit 9811dce8 authored by dpapad's avatar dpapad Committed by Commit bot

MD Settings: Remove usage of 'autofocus' from settings-action-menu.

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

Review-Url: https://codereview.chromium.org/2438423002
Cr-Commit-Position: refs/heads/master@{#427248}
parent 51e83233
...@@ -12,12 +12,6 @@ Polymer({ ...@@ -12,12 +12,6 @@ Polymer({
*/ */
options_: null, options_: null,
/**
* Index of the currently focused item.
* @private {number}
*/
focusedIndex_: -1,
/** /**
* Reference to the bound window's resize listener, such that it can be * Reference to the bound window's resize listener, such that it can be
* removed on detach. * removed on detach.
...@@ -93,11 +87,12 @@ Polymer({ ...@@ -93,11 +87,12 @@ Polymer({
var counter = 0; var counter = 0;
var nextOption = null; var nextOption = null;
var numOptions = this.options_.length; var numOptions = this.options_.length;
var focusedIndex = Array.prototype.indexOf.call(
this.options_, this.root.activeElement);
do { do {
this.focusedIndex_ = focusedIndex = (numOptions + focusedIndex + step) % numOptions;
(numOptions + this.focusedIndex_ + step) % numOptions; nextOption = this.options_[focusedIndex];
nextOption = this.options_[this.focusedIndex_];
if (nextOption.disabled || nextOption.hidden) if (nextOption.disabled || nextOption.hidden)
nextOption = null; nextOption = null;
counter++; counter++;
...@@ -119,23 +114,6 @@ Polymer({ ...@@ -119,23 +114,6 @@ Polymer({
* @param {!Element} anchorElement * @param {!Element} anchorElement
*/ */
showAt: function(anchorElement) { showAt: function(anchorElement) {
var rect = anchorElement.getBoundingClientRect();
// Ensure that the correct item is focused when the dialog is shown, by
// setting the 'autofocus' attribute.
this.focusedIndex_ = -1;
var nextOption = this.getNextOption_(1);
/** @suppress {checkTypes} */
(function(options) {
options.forEach(function(option) {
option.removeAttribute('autofocus');
});
})(this.options_);
if (nextOption)
nextOption.setAttribute('autofocus', true);
this.onWindowResize_ = this.onWindowResize_ || function() { this.onWindowResize_ = this.onWindowResize_ || function() {
if (this.open) if (this.open)
this.close(); this.close();
...@@ -144,6 +122,7 @@ Polymer({ ...@@ -144,6 +122,7 @@ Polymer({
this.showModal(); this.showModal();
var rect = anchorElement.getBoundingClientRect();
if (new settings.DirectionDelegateImpl().isRtl()) { if (new settings.DirectionDelegateImpl().isRtl()) {
var right = window.innerWidth - rect.left - this.offsetWidth; var right = window.innerWidth - rect.left - this.offsetWidth;
this.style.right = right + 'px'; this.style.right = right + 'px';
......
...@@ -17,6 +17,7 @@ suite('SettingsActionMenu', function() { ...@@ -17,6 +17,7 @@ suite('SettingsActionMenu', function() {
<button id="dots">...</button> <button id="dots">...</button>
<dialog is="settings-action-menu"> <dialog is="settings-action-menu">
<button class="dropdown-item">Un</button> <button class="dropdown-item">Un</button>
<hr>
<button class="dropdown-item">Dos</button> <button class="dropdown-item">Dos</button>
<button class="dropdown-item">Tres</button> <button class="dropdown-item">Tres</button>
</dialog> </dialog>
...@@ -33,32 +34,23 @@ suite('SettingsActionMenu', function() { ...@@ -33,32 +34,23 @@ suite('SettingsActionMenu', function() {
}); });
test('focus after showing', function() { test('focus after showing', function() {
/** @param {!HTMLElement} element */
function assertFocused(element) {
assertEquals(element, menu.root.activeElement);
items.forEach(function(item, i) {
assertEquals(element === item, item.hasAttribute('autofocus'));
});
}
menu.showAt(document.querySelector('#dots')); menu.showAt(document.querySelector('#dots'));
assertFocused(items[0]); assertEquals(menu.root.activeElement, items[0]);
menu.close(); menu.close();
items[0].hidden = true; items[0].hidden = true;
menu.showAt(document.querySelector('#dots')); menu.showAt(document.querySelector('#dots'));
assertFocused(items[1]); assertEquals(menu.root.activeElement, items[1]);
menu.close(); menu.close();
items[1].hidden = true; items[1].hidden = true;
menu.showAt(document.querySelector('#dots')); menu.showAt(document.querySelector('#dots'));
assertFocused(items[2]); assertEquals(menu.root.activeElement, items[2]);
menu.close(); menu.close();
items[2].disabled = true; items[2].disabled = true;
menu.showAt(document.querySelector('#dots')); menu.showAt(document.querySelector('#dots'));
assertEquals(null, menu.root.activeElement); assertEquals(null, menu.root.activeElement);
assertEquals(0, menu.querySelectorAll('[autofocus]').length);
}); });
test('focus after down/up arrow', function() { test('focus after down/up arrow', function() {
......
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