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

Unified Diff: third_party/polymer/v1_0/components-chromium/iron-list/iron-list-extracted.js

Issue 2794173002: MD Settings: Fix iron-list losing focus when items change. (Closed)
Patch Set: merge Created 3 years, 7 months 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 | « third_party/polymer/v1_0/chromium.patch ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/polymer/v1_0/components-chromium/iron-list/iron-list-extracted.js
diff --git a/third_party/polymer/v1_0/components-chromium/iron-list/iron-list-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-list/iron-list-extracted.js
index 780e6cb4617dcfdf04eec8a459bbfe14a4b72869..bb2f6aad64e8ecaf56d5821b9dbe97f45c8b1ea0 100644
--- a/third_party/polymer/v1_0/components-chromium/iron-list/iron-list-extracted.js
+++ b/third_party/polymer/v1_0/components-chromium/iron-list/iron-list-extracted.js
@@ -126,6 +126,14 @@
scrollOffset: {
type: Number,
value: 0
+ },
+
+ /**
+ * If set to true, focus on an element will be preserved after rerender.
+ */
+ preserveFocus: {
+ type: Boolean,
+ value: false
}
},
@@ -895,6 +903,15 @@
* to `items`, splices or updates to a single item.
*/
_itemsChanged: function(change) {
+ var rendering = /^items(\.splices){0,1}$/.test(change.path);
+ var lastFocusedIndex, focusedElement;
+ if (rendering && this.preserveFocus) {
+ lastFocusedIndex = this._focusedIndex;
+ focusedElement = this.querySelector('* /deep/ *:focus');
+ }
+
+ var preservingFocus = rendering && this.preserveFocus && focusedElement;
+
if (change.path === 'items') {
this._virtualStart = 0;
this._physicalTop = 0;
@@ -907,12 +924,11 @@
this._physicalItems = this._physicalItems || [];
this._physicalSizes = this._physicalSizes || [];
this._physicalStart = 0;
- if (this._scrollTop > this._scrollOffset) {
+ if (this._scrollTop > this._scrollOffset && !preservingFocus) {
this._resetScrollPosition(0);
}
this._removeFocusedItem();
this._debounceTemplate(this._render);
-
} else if (change.path === 'items.splices') {
this._adjustVirtualIndex(change.value.indexSplices);
this._virtualCount = this.items ? this.items.length : 0;
@@ -921,6 +937,17 @@
} else {
this._forwardItemPath(change.path.split('.').slice(1).join('.'), change.value);
}
+
+ // If the list was in focus when updated, preserve the focus on item.
+ if (preservingFocus) {
+ Polymer.dom.flush();
+ focusedElement.blur(); // paper- elements breaks when focused twice.
+ this._focusPhysicalItem(
+ Math.min(this.items.length - 1, lastFocusedIndex));
+ if (!this._isIndexVisible(this._focusedIndex)) {
+ this.scrollToIndex(this._focusedIndex);
+ }
+ }
},
/**
« no previous file with comments | « third_party/polymer/v1_0/chromium.patch ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698