Commit c22120c7 authored by Jon Mann's avatar Jon Mann Committed by Commit Bot

Default focus on Connect or Disconnect button on network details page.

Bug: 991928
Change-Id: I22f5e2e41daa6bc94110ce0641c7e9df510517e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824437
Commit-Queue: Jon Mann <jonmann@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700852}
parent 4bf59d9c
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
} }
</style> </style>
<cr-button class$="[[getClass_(actionButton)]]" <cr-button class$="[[actionClass_]]"
disabled="[[!buttonEnabled_(enforced_, disabled)]]"> disabled="[[!buttonEnabled_(enforced_, disabled)]]">
[[label]] [[label]]
</cr-button> </cr-button>
......
...@@ -11,11 +11,6 @@ Polymer({ ...@@ -11,11 +11,6 @@ Polymer({
], ],
properties: { properties: {
actionButton: {
type: Boolean,
value: false,
},
endJustified: { endJustified: {
type: Boolean, type: Boolean,
value: false, value: false,
...@@ -30,6 +25,12 @@ Polymer({ ...@@ -30,6 +25,12 @@ Polymer({
reflectToAttribute: true, reflectToAttribute: true,
}, },
/** @private */
actionClass_: {
type: String,
value: ''
},
/** @private */ /** @private */
enforced_: { enforced_: {
type: Boolean, type: Boolean,
...@@ -38,6 +39,18 @@ Polymer({ ...@@ -38,6 +39,18 @@ Polymer({
}, },
}, },
/** @override */
attached: function() {
if (this.classList.contains('action-button')) {
this.actionClass_ = 'action-button';
}
},
/** Focus on the inner cr-button. */
focus: function() {
this.$$('cr-button').focus();
},
/** /**
* @param {!Event} e * @param {!Event} e
* @private * @private
...@@ -48,15 +61,6 @@ Polymer({ ...@@ -48,15 +61,6 @@ Polymer({
e.stopPropagation(); e.stopPropagation();
}, },
/**
* @param {!boolean} actionButton
* @return {string} Class of the cr-button.
* @private
*/
getClass_: function(actionButton) {
return actionButton ? 'action-button' : '';
},
/** /**
* @param {!boolean} enforced * @param {!boolean} enforced
* @param {!boolean} disabled * @param {!boolean} disabled
......
...@@ -117,7 +117,8 @@ ...@@ -117,7 +117,8 @@
</cr-button> </cr-button>
<!-- Use policy properties from vpn_config_allowed to indicate when that <!-- Use policy properties from vpn_config_allowed to indicate when that
pref disables buttons in this row. --> pref disables buttons in this row. -->
<controlled-button id="connect" action-button on-click="onConnectTap_" <controlled-button id="connect" class="action-button"
on-click="onConnectTap_"
hidden$="[[!showConnect_(managedProperties_, globalPolicy, hidden$="[[!showConnect_(managedProperties_, globalPolicy,
managedNetworkAvailable)]]" managedNetworkAvailable)]]"
disabled="[[!enableConnect_(managedProperties_, defaultNetwork, disabled="[[!enableConnect_(managedProperties_, defaultNetwork,
...@@ -127,7 +128,7 @@ ...@@ -127,7 +128,7 @@
pref="[[getFakeVpnConfigPrefForEnforcement_(managedProperties_, pref="[[getFakeVpnConfigPrefForEnforcement_(managedProperties_,
prefs.vpn_config_allowed)]]"> prefs.vpn_config_allowed)]]">
</controlled-button> </controlled-button>
<controlled-button id="disconnect" action-button <controlled-button id="disconnect" class="action-button"
on-click="onDisconnectTap_" on-click="onDisconnectTap_"
hidden$="[[!showDisconnect_(managedProperties_)]]" hidden$="[[!showDisconnect_(managedProperties_)]]"
label="$i18n{networkButtonDisconnect}" label="$i18n{networkButtonDisconnect}"
......
...@@ -344,10 +344,9 @@ Polymer({ ...@@ -344,10 +344,9 @@ Polymer({
if (!this.didSetFocus_) { if (!this.didSetFocus_) {
// Focus a button once the initial state is set. // Focus a button once the initial state is set.
this.didSetFocus_ = true; this.didSetFocus_ = true;
const button = this.$$('#titleDiv .action-button:not([hidden])') || const button = this.$$('#titleDiv .action-button:not([hidden])');
this.$$('#titleDiv cr-button:not([hidden])');
if (button) { if (button) {
setTimeout(() => button.focus()); Polymer.RenderStatus.afterNextRender(this, () => button.focus());
} }
} }
......
...@@ -74,8 +74,13 @@ suite('controlled button', function() { ...@@ -74,8 +74,13 @@ suite('controlled button', function() {
test('action-button', function() { test('action-button', function() {
assertNotEquals( assertNotEquals(
'action-button', controlledButton.$$('cr-button').className); 'action-button', controlledButton.$$('cr-button').className);
controlledButton.actionButton = true;
let controlledActionButton = document.createElement('controlled-button');
controlledActionButton.pref = uncontrolledPref;
controlledActionButton.className = 'action-button';
document.body.appendChild(controlledActionButton);
Polymer.dom.flush(); Polymer.dom.flush();
assertEquals('action-button', controlledButton.$$('cr-button').className); assertEquals(
'action-button', controlledActionButton.$$('cr-button').className);
}); });
}); });
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