Network config: Fix focus for configured networks

TBR=stevenjb@chromium.org

(cherry picked from commit abd2d4ed8622d96e84a4a78ae3daae86df98a5e9)

Bug: 811659
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Id8937bcbd6828c8fc38b0e27e6505582ce6c25ca
Reviewed-on: https://chromium-review.googlesource.com/920647
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#537107}
Reviewed-on: https://chromium-review.googlesource.com/929346
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#540}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/ui/webui/resources/cr_components/chromeos/network/network_config.js b/ui/webui/resources/cr_components/chromeos/network/network_config.js
index 26c479f7..2e310e1 100644
--- a/ui/webui/resources/cr_components/chromeos/network/network_config.js
+++ b/ui/webui/resources/cr_components/chromeos/network/network_config.js
@@ -343,19 +343,18 @@
     this.guid = this.networkProperties.GUID;
     this.type = this.networkProperties.Type;
     if (this.guid) {
-      this.networkingPrivate.getProperties(
-          this.guid, this.getPropertiesCallback_.bind(this));
+      this.networkingPrivate.getProperties(this.guid, (properties) => {
+        this.getPropertiesCallback_(properties);
+        this.focusFirstInput_();
+      });
+    } else {
+      this.async(() => {
+        this.focusFirstInput_();
+      });
     }
     this.onCertificateListsChanged_();
     this.updateIsConfigured_();
     this.setShareNetwork_();
-    requestAnimationFrame(() => {
-      var e = this.$$(
-          'network-config-input:not([disabled]),' +
-          'network-config-select:not([disabled])');
-      if (e)
-        e.focus();
-    });
   },
 
   saveOrConnect: function() {
@@ -386,6 +385,16 @@
   },
 
   /** @private */
+  focusFirstInput_: function() {
+    Polymer.dom.flush();
+    var e = this.$$(
+        'network-config-input:not([disabled]),' +
+        'network-config-select:not([disabled])');
+    if (e)
+      e.focus();
+  },
+
+  /** @private */
   connectIfConfigured_: function() {
     if (!this.isConfigured_)
       return;