Commit bef66dbc authored by James Cook's avatar James Cook Committed by Commit Bot

settings: Focus sync passphrase field after entering wrong passphrase

The user is likely to try re-entering their passphrase, so ensure
focus stays in the input field.

Convert the Print Preview PIN settings element to use the same
approach to focus, so callers aren't depending on internal
implementation details of cr-input.

Bug: 805829
Test: See bug. sign in to account with sync passphrase, enter
  incorrect phrase, focus returns to input field. Tested with both
  Chrome OS and Linux.

Change-Id: I012f5b5368654c8b0f36b66f9fd07124d394c9a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832632Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Auto-Submit: James Cook <jamescook@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702032}
parent f817464d
...@@ -66,7 +66,7 @@ Polymer({ ...@@ -66,7 +66,7 @@ Polymer({
/** @private */ /** @private */
onCollapseChanged_: function() { onCollapseChanged_: function() {
if (this.pinEnabled_) { if (this.pinEnabled_) {
/** @type {!CrInputElement} */ (this.$.pinValue).inputElement.focus(); /** @type {!CrInputElement} */ (this.$.pinValue).focusInput();
} }
}, },
......
...@@ -506,7 +506,10 @@ Polymer({ ...@@ -506,7 +506,10 @@ Polymer({
case settings.PageStatus.PASSPHRASE_FAILED: case settings.PageStatus.PASSPHRASE_FAILED:
if (this.pageStatus_ == this.pages_.CONFIGURE && this.syncPrefs && if (this.pageStatus_ == this.pages_.CONFIGURE && this.syncPrefs &&
this.syncPrefs.passphraseRequired) { this.syncPrefs.passphraseRequired) {
this.$$('#existingPassphraseInput').invalid = true; const passphraseInput = /** @type {!CrInputElement} */ (
this.$$('#existingPassphraseInput'));
passphraseInput.invalid = true;
passphraseInput.focusInput();
} }
return; return;
} }
......
...@@ -225,7 +225,7 @@ Polymer({ ...@@ -225,7 +225,7 @@ Polymer({
/** @private */ /** @private */
onFocus_: function() { onFocus_: function() {
if (!this.focusInput_()) { if (!this.focusInput()) {
return; return;
} }
// Always select the <input> element on focus. TODO(stevenjb/scottchen): // Always select the <input> element on focus. TODO(stevenjb/scottchen):
...@@ -235,10 +235,12 @@ Polymer({ ...@@ -235,10 +235,12 @@ Polymer({
}, },
/** /**
* Focuses the input element.
* TODO(crbug.com/882612): Replace this with focus() after resolving the text
* selection issue described in onFocus_().
* @return {boolean} Whether the <input> element was focused. * @return {boolean} Whether the <input> element was focused.
* @private
*/ */
focusInput_: function() { focusInput: function() {
if (this.shadowRoot.activeElement == this.inputElement) { if (this.shadowRoot.activeElement == this.inputElement) {
return false; return false;
} }
...@@ -346,7 +348,7 @@ Polymer({ ...@@ -346,7 +348,7 @@ Polymer({
* @param {number=} end * @param {number=} end
*/ */
select: function(start, end) { select: function(start, end) {
this.focusInput_(); this.focusInput();
if (start !== undefined && end !== undefined) { if (start !== undefined && end !== undefined) {
this.inputElement.setSelectionRange(start, end); this.inputElement.setSelectionRange(start, end);
} else { } else {
......
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