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: ui/webui/resources/cr_elements/network/cr_network_list.js

Issue 2705793002: cr-network-select: implement focus() (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | ui/webui/resources/cr_elements/network/cr_network_select.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/cr_elements/network/cr_network_list.js
diff --git a/ui/webui/resources/cr_elements/network/cr_network_list.js b/ui/webui/resources/cr_elements/network/cr_network_list.js
index 82b5fc70658c3bfd4b8553983412ad5cf1e593cf..54588416fee54bd71bf5d1f3734532f10b6f7d5a 100644
--- a/ui/webui/resources/cr_elements/network/cr_network_list.js
+++ b/ui/webui/resources/cr_elements/network/cr_network_list.js
@@ -67,12 +67,46 @@ Polymer({
observers: ['updateListItems_(networks, customItems)'],
+ /**
+ * True if element is focused, but dom-repeat is not rendered yet.
+ * @private
+ */
+ needFocus_: false,
+
+ attached: function() {
+ var self = this;
+ var observer = new MutationObserver(function() {
+ self.checkFocus_();
+ });
+ observer.observe(this.$.networkList, { childList: true });
+ },
+
+ focus: function() {
+ this.needFocus_ = false;
+ var items = this.$.networkList.getElementsByTagName('cr-network-list-item');
+ if (items && items[0]) {
+ items[0].focus();
+ } else {
+ this.needFocus_ = true;
+ }
+ },
+
+ /**
+ * Triggers delayed focus.
+ * @private
+ */
+ checkFocus_: function() {
+ if (this.needFocus_)
+ this.focus();
+ },
+
/** @private */
updateListItems_: function() {
this.saveScroll(this.$.networkList);
this.listItems_ = this.networks.concat(this.customItems);
this.restoreScroll(this.$.networkList);
this.updateScrollableContents();
+ this.checkFocus_();
},
/**
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/network/cr_network_select.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698