Commit 73719d8e authored by Jon Mann's avatar Jon Mann Committed by Commit Bot

Revert "Maintain focus when items in a network-list are updated."

This reverts commit ede86024.

Reason for revert: Breaks network selection in OOBE

Original change's description:
> Maintain focus when items in a network-list are updated.
>
> Previously, focus would jump to the first element when
> the underlying network list was updated.  This fix
> attempts to maintain focus on a particular network if it
> is still present, otherwise it tries to stay on the same
> index, and finally falls back to the first element.
>
> Fixed: 1005934
> Change-Id: I9a7e2307bc604f8ba08b659e22f80ba88ad66156
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1920188
> Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
> Commit-Queue: Jon Mann <jonmann@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#721367}

TBR=khorimoto@chromium.org,jonmann@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1031994, 1032265
Change-Id: I31a30d106b61cb917f4a489abf17097476db40e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975162
Commit-Queue: Jon Mann <jonmann@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726240}
parent 530cfbb9
...@@ -76,73 +76,28 @@ Polymer({ ...@@ -76,73 +76,28 @@ Polymer({
/** @private {boolean} */ /** @private {boolean} */
focusRequested_: false, focusRequested_: false,
/**
* GUID of the focused network before the list is updated. This
* is used to re-apply focus to the same network if possible.
* @private {string}
*/
focusedGuidBeforeUpdate_: '',
/**
* Index of the focused network before the list is updated. This
* is used to re-apply focus when the previously focused network
* is no longer listed.
* @private {number}
*/
focusedIndexBeforeUpdate_: -1,
focus: function() { focus: function() {
this.focusRequested_ = true; this.focusRequested_ = true;
this.focusFirstItem_(); this.focusFirstItem_();
}, },
/** @private */
saveFocus_: function() {
if (this.shadowRoot.activeElement &&
this.shadowRoot.activeElement.is === 'network-list-item') {
const focusedNetwork = /** @type {!NetworkList.NetworkListItem} */ (
this.shadowRoot.activeElement);
if (focusedNetwork.item && focusedNetwork.item.guid) {
this.focusedGuidBeforeUpdate = focusedNetwork.item.guid;
this.focusedIndexBeforeUpdate_ = this.listItems_.findIndex(
n => n.guid === this.focusedGuidBeforeUpdate);
return;
}
}
this.focusedGuidBeforeUpdate = '';
this.focusedIndexBeforeUpdate_ = -1;
},
/** @private */
restoreFocus_: function() {
if (this.focusedGuidBeforeUpdate) {
let currentIndex = this.listItems_.findIndex(
(n) => n.guid === this.focusedGuidBeforeUpdate);
if (currentIndex < 0) {
currentIndex = this.focusedIndexBeforeUpdate_ < this.listItems_.length ?
this.focusedIndexBeforeUpdate_ :
0;
}
this.$.networkList.focusItem(currentIndex);
} else if (this.focusRequested_) {
this.async(function() {
this.focusFirstItem_();
});
}
},
/** @private */ /** @private */
updateListItems_: function() { updateListItems_: function() {
this.saveScroll(this.$.networkList); this.saveScroll(this.$.networkList);
this.saveFocus_(); const beforeNetworks = this.customItems.filter(function(item) {
const beforeNetworks = return item.showBeforeNetworksList == true;
this.customItems.filter(n => n.showBeforeNetworksList == true); });
const afterNetworks = const afterNetworks = this.customItems.filter(function(item) {
this.customItems.filter(n => n.showBeforeNetworksList == false); return item.showBeforeNetworksList == false;
});
this.listItems_ = beforeNetworks.concat(this.networks, afterNetworks); this.listItems_ = beforeNetworks.concat(this.networks, afterNetworks);
this.restoreScroll(this.$.networkList); this.restoreScroll(this.$.networkList);
this.updateScrollableContents(); this.updateScrollableContents();
this.restoreFocus_(); if (this.focusRequested_) {
this.async(function() {
this.focusFirstItem_();
});
}
}, },
/** @private */ /** @private */
......
...@@ -23,9 +23,3 @@ NetworkList.CustomItemState; ...@@ -23,9 +23,3 @@ NetworkList.CustomItemState;
/** @typedef {OncMojo.NetworkStateProperties|NetworkList.CustomItemState} */ /** @typedef {OncMojo.NetworkStateProperties|NetworkList.CustomItemState} */
NetworkList.NetworkListItemType; NetworkList.NetworkListItemType;
/**
* Custom data for implementation specific network list items.
* @typedef {{item: (!NetworkList.NetworkListItemType|undefined)}}
*/
NetworkList.NetworkListItem;
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