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

Unified Diff: third_party/polymer/v1_0/chromium.patch

Issue 2794173002: MD Settings: Fix iron-list losing focus when items change. (Closed)
Patch Set: add the patch file change Created 3 years, 8 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
Index: third_party/polymer/v1_0/chromium.patch
diff --git a/third_party/polymer/v1_0/chromium.patch b/third_party/polymer/v1_0/chromium.patch
index 8b99b23f099dfaa63080fe6a058cbaf9e4286782..f17d16a458e2ae11f02a4f09971977e953e2195e 100644
--- a/third_party/polymer/v1_0/chromium.patch
+++ b/third_party/polymer/v1_0/chromium.patch
@@ -24,3 +24,70 @@ index 78a2a9ec621c..8b776dd790ea 100644
},
_ariaDescribedByChanged: function(ariaDescribedBy) {
+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 9e9ec02f9c9c..eb492f1e3f8a 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
+ }
+ },
+
+@@ -894,6 +902,15 @@
+ * to `items`, splices or updates to a single item.
+ */
+ _itemsChanged: function(change) {
++ var rendering = ['items', 'items.splices'].includes(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;
+@@ -906,12 +923,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;
+@@ -920,6 +936,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);
++ }
++ }
+ },
+
+ /**

Powered by Google App Engine
This is Rietveld 408576698