Commit 48f47249 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

Settings: settings-internet-page, replace /deep/ selector with selector in function

Bug: 860069
Change-Id: Ifa72a55db0f15050bb115a6f50c319124ec367ed
Reviewed-on: https://chromium-review.googlesource.com/1155929
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580038}
parent 2b73f108
...@@ -125,7 +125,7 @@ Polymer({ ...@@ -125,7 +125,7 @@ Polymer({
} }
}, },
/** @private {!Map<string, string>} */ /** @private {!Map<string, Element>} */
focusConfig_: { focusConfig_: {
type: Object, type: Object,
value: function() { value: function() {
...@@ -239,18 +239,19 @@ Polymer({ ...@@ -239,18 +239,19 @@ Polymer({
return; return;
// Focus the subpage arrow where appropriate. // Focus the subpage arrow where appropriate.
let selector; let element;
if (route == settings.routes.INTERNET_NETWORKS) { if (route == settings.routes.INTERNET_NETWORKS) {
// iron-list makes the correct timing to focus an item in the list // iron-list makes the correct timing to focus an item in the list
// very complicated, and the item may not exist, so just focus the // very complicated, and the item may not exist, so just focus the
// entire list for now. // entire list for now.
selector = '* /deep/ #networkList'; element = this.$$('settings-internet-subpage').$$('#networkList');
} else if (this.detailType_) { } else if (this.detailType_) {
selector = element = this.$$('network-summary')
'* /deep/ #' + this.detailType_ + ' /deep/ .subpage-arrow button'; .$$(`#${this.detailType_}`)
.$$('.subpage-arrow button');
} }
if (selector && this.querySelector(selector)) if (element)
this.focusConfig_.set(oldRoute.path, selector); this.focusConfig_.set(oldRoute.path, element);
else else
this.focusConfig_.delete(oldRoute.path); this.focusConfig_.delete(oldRoute.path);
}, },
......
...@@ -32,9 +32,9 @@ Polymer({ ...@@ -32,9 +32,9 @@ Polymer({
/** /**
* A Map specifying which element should be focused when exiting a subpage. * A Map specifying which element should be focused when exiting a subpage.
* The key of the map holds a settings.Route path, and the value holds * The key of the map holds a settings.Route path, and the value holds
* either a query selector that identifies the desired element or a function * either a query selector that identifies the desired element, an element
* to be run when a neon-animation-finish event is handled. * or a function to be run when a neon-animation-finish event is handled.
* @type {?Map<string, (string|Function)>} * @type {?Map<string, (string|Element|Function)>}
*/ */
focusConfig: Object, focusConfig: Object,
}, },
...@@ -107,20 +107,23 @@ Polymer({ ...@@ -107,20 +107,23 @@ Polymer({
if (!e.detail.item.matches(query)) if (!e.detail.item.matches(query))
return; return;
const selectorOrFunction = this.focusConfig.get(this.previousRoute_.path); let pathConfig = this.focusConfig.get(this.previousRoute_.path);
if (selectorOrFunction) { if (pathConfig) {
let handler;
if (typeof pathConfig == 'function') {
handler = pathConfig;
} else {
handler = () => {
if (typeof pathConfig == 'string')
pathConfig = assert(this.querySelector(pathConfig));
cr.ui.focusWithoutInk(/** @type {!Element} */ (pathConfig));
};
}
// neon-animatable has "display: none" until the animation finishes, // neon-animatable has "display: none" until the animation finishes,
// so calling focus() on any of its children has no effect until // so calling focus() on any of its children has no effect until
// "display:none" is removed. Therefore, don't set focus from within // "display:none" is removed. Therefore, don't set focus from within
// the currentRouteChanged callback. // the currentRouteChanged callback.
listenOnce(this, 'neon-animation-finish', () => { listenOnce(this, 'neon-animation-finish', handler);
if (typeof selectorOrFunction == 'function') {
selectorOrFunction();
} else {
const selector = /** @type {string} */ (selectorOrFunction);
cr.ui.focusWithoutInk(assert(this.querySelector(selector)));
}
});
} }
}, },
......
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