Skip to content

Commit 80f31c7

Browse files
natiahlyiChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
[Passwords Import] Focus on first actionable element
Bug: 1440694 Change-Id: I5e24869d6c6becaec6ee93038327e7c51003ae9e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4482441 Reviewed-by: Viktor Semeniuk <vsemeniuk@google.com> Commit-Queue: Andrii Natiahlyi <natiahlyi@google.com> Cr-Commit-Position: refs/heads/main@{#1136553}
1 parent 5b68321 commit 80f31c7

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

chrome/browser/resources/settings/autofill_page/passwords_import_dialog.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@
150150
<div slot="body">
151151
<select class="md-select" id="storePicker"
152152
aria-description="$i18n{importPasswordsStorePickerA11yDescription}"
153-
hidden="[[!shouldShowStorePicker_(isAccountStoreUser, dialogState)]]"
154-
autofocus="[[shouldShowStorePicker_(isAccountStoreUser,
155-
dialogState)]]">
153+
hidden="[[!shouldShowStorePicker_(isAccountStoreUser, dialogState)]]">
156154
<option value="[[storeOptionEnum_.ACCOUNT]]">
157155
[[getStoreOptionAccountText_(accountEmail, dialogState)]]
158156
</option>

chrome/browser/resources/settings/autofill_page/passwords_import_dialog.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import {CrCheckboxElement} from 'chrome://resources/cr_elements/cr_checkbox/cr_c
2222
import {CrDialogElement} from 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js';
2323
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
2424
import {assert, assertNotReached} from 'chrome://resources/js/assert_ts.js';
25+
import {focusWithoutInk} from 'chrome://resources/js/focus_without_ink.js';
2526
import {sanitizeInnerHtml} from 'chrome://resources/js/parse_html_subset.js';
2627
import {PluralStringProxyImpl} from 'chrome://resources/js/plural_string_proxy.js';
27-
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
28+
import {afterNextRender, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
2829

2930
import {loadTimeData} from '../i18n_setup.js';
3031

@@ -106,7 +107,10 @@ export class PasswordsImportDialogElement extends
106107

107108
static get properties() {
108109
return {
109-
dialogState: Number,
110+
dialogState: {
111+
type: Number,
112+
observer: 'focusOnFirstActionableItem_',
113+
},
110114

111115
importDialogStateEnum_: {
112116
type: Object,
@@ -205,6 +209,24 @@ export class PasswordsImportDialogElement extends
205209
this.dialogState = ImportDialogState.START;
206210
}
207211

212+
private focusOnFirstActionableItem_() {
213+
afterNextRender(this, () => {
214+
let elementToFocus = this.$.close as HTMLElement;
215+
if (this.isState_(ImportDialogState.CONFLICTS)) {
216+
const firstCheckbox =
217+
this.$.conflictsList.querySelector('cr-checkbox') as HTMLElement;
218+
if (firstCheckbox) {
219+
elementToFocus = firstCheckbox;
220+
}
221+
} else if (!this.shouldHideDeleteFileOption_()) {
222+
elementToFocus = this.$.deleteFileOption as HTMLElement;
223+
} else if (this.shouldShowStorePicker_()) {
224+
elementToFocus = this.$.storePicker as HTMLElement;
225+
}
226+
focusWithoutInk(elementToFocus);
227+
});
228+
}
229+
208230
private computeConflictsListClass_(): string {
209231
return this.inProgress_ ? 'disabled-conflicts-list' : '';
210232
}
@@ -376,7 +398,6 @@ export class PasswordsImportDialogElement extends
376398
default:
377399
assertNotReached();
378400
}
379-
this.$.close.focus();
380401
}
381402

382403
private async handleSuccess_() {
@@ -418,8 +439,6 @@ export class PasswordsImportDialogElement extends
418439
this.descriptionText_ = sanitizeInnerHtml(descriptionText);
419440
}
420441
this.dialogState = ImportDialogState.SUCCESS;
421-
422-
this.$.close.focus();
423442
}
424443

425444
private getStoreOptionAccountText_(): string {

0 commit comments

Comments
 (0)