Commit 44501c99 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Iron List: Remove usage of /deep/

/deep/ selector no longer works in Polymer 2. Update iron-list to find
the focused element differently.

Bug: 899113
Change-Id: I5c548adbe680a5980638e4905bffdf7fceb977e6
Reviewed-on: https://chromium-review.googlesource.com/c/1316443Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606715}
parent 986629bb
......@@ -27,8 +27,44 @@ index 43c59653a39b..26652936735c 100644
+ value: false
}
},
@@ -786,6 +794,39 @@
newGrid && this._updateGridMetrics();
},
@@ -791,6 +799,15 @@
+ /**
+ * Finds and returns the focused element (both within self and children's
+ * Shadow DOM).
+ * @return {?HTMLElement}
+ */
+ _getFocusedElement: function() {
+ function doSearch(node, query) {
+ let result = null;
+ let type = node.nodeType;
+ if (type == Node.ELEMENT_NODE || type == Node.DOCUMENT_FRAGMENT_NODE)
+ result = node.querySelector(query);
+ if (result)
+ return result;
+
+ let child = node.firstChild;
+ while (child !== null && result === null) {
+ result = doSearch(child, query);
+ child = child.nextSibling;
+ }
+ if (result)
+ return result;
+
+ const shadowRoot = node.shadowRoot;
+ return shadowRoot ? doSearch(shadowRoot, query) : null;
+ }
+
+ // Find out if any of the items are focused first, and only search
+ // recursively in the item that contains focus, to avoid a slow
+ // search of the entire list.
+ const focusWithin = doSearch(this, ':focus-within');
+ return focusWithin ? doSearch(focusWithin, ':focus') : null;
+ },
+
@@ -791,6 +836,15 @@
* to `items`, splices or updates to a single item.
*/
_itemsChanged: function(change) {
......@@ -44,7 +80,7 @@ index 43c59653a39b..26652936735c 100644
if (change.path === 'items') {
this._virtualStart = 0;
this._physicalTop = 0;
@@ -804,7 +821,7 @@
@@ -804,7 +858,7 @@
this._physicalItems = this._physicalItems || [];
this._physicalSizes = this._physicalSizes || [];
this._physicalStart = 0;
......@@ -53,7 +89,7 @@ index 43c59653a39b..26652936735c 100644
this._resetScrollPosition(0);
}
this._removeFocusedItem();
@@ -826,6 +843,17 @@
@@ -826,6 +880,17 @@
} else if (change.path !== 'items.length') {
this._forwardItemPath(change.path, change.value);
}
......
......@@ -794,6 +794,39 @@
newGrid && this._updateGridMetrics();
},
/**
* Finds and returns the focused element (both within self and children's
* Shadow DOM).
* @return {?HTMLElement}
*/
_getFocusedElement: function() {
function doSearch(node, query) {
let result = null;
let type = node.nodeType;
if (type == Node.ELEMENT_NODE || type == Node.DOCUMENT_FRAGMENT_NODE)
result = node.querySelector(query);
if (result)
return result;
let child = node.firstChild;
while (child !== null && result === null) {
result = doSearch(child, query);
child = child.nextSibling;
}
if (result)
return result;
const shadowRoot = node.shadowRoot;
return shadowRoot ? doSearch(shadowRoot, query) : null;
}
// Find out if any of the items are focused first, and only search
// recursively in the item that contains focus, to avoid a slow
// search of the entire list.
const focusWithin = doSearch(this, ':focus-within');
return focusWithin ? doSearch(focusWithin, ':focus') : null;
},
/**
* Called when the items have changed. That is, reassignments
* to `items`, splices or updates to a single item.
......@@ -803,7 +836,7 @@
var lastFocusedIndex, focusedElement;
if (rendering && this.preserveFocus) {
lastFocusedIndex = this._focusedVirtualIndex;
focusedElement = this.querySelector('* /deep/ *:focus');
focusedElement = this._getFocusedElement();
}
var preservingFocus = rendering && this.preserveFocus && focusedElement;
......
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