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

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: 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
« 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 9e9ec02f9c9c4286011e6eb37a6201fe99ae70aa..eb492f1e3f8a1e8cbfa63f0337238cd2d3db1c86 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);
dpapad 2017/05/23 22:19:43 Nit (optional): Maybe use a regex instead (to avoi
scottchen 2017/05/24 21:34:35 Done.
+ 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);
+ }
stevenjb 2017/05/09 17:14:00 Can we do something like: var idx = Math.min(this
scottchen 2017/05/22 22:57:31 This would not work as intended: focusedElement
stevenjb 2017/05/22 23:14:54 It's been a while, but I think I was being hand-wa
scottchen 2017/05/23 21:43:49 focusedItem at this point is already reset to 0 (t
stevenjb 2017/05/23 21:53:47 OK, lgtm then
+ }
},
/**
« 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