Auto focus on the first input field

When opening the Create New dialog in Browse > Repositories and
Browse > Groups, auto focus on the first input field to avoid
unnecessary clicks.

Bug: Issue 12536
Change-Id: Ieae5f1e5eac1cd51a101cc7fcab4a1d78582faaf
This commit is contained in:
Dhruv Srivastava
2021-02-02 12:43:27 +01:00
parent c2818fbe5b
commit 26320751cf
6 changed files with 18 additions and 4 deletions

View File

@@ -178,7 +178,9 @@ export class GrAdminGroupList extends ListViewMixin(
}
_handleCreateClicked() {
this.$.createOverlay.open();
this.$.createOverlay.open().then(() => {
this.$.createNewModal.focus();
});
}
_visibleToAll(item: GroupInfo) {

View File

@@ -155,7 +155,8 @@ suite('gr-admin-group-list tests', () => {
});
test('_handleCreateClicked opens modal', () => {
const openStub = sinon.stub(element.$.createOverlay, 'open');
const openStub = sinon.stub(element.$.createOverlay, 'open').returns(
Promise.resolve());
element._handleCreateClicked();
assert.isTrue(openStub.called);
});

View File

@@ -55,6 +55,10 @@ export class GrCreateGroupDialog extends GestureEventListeners(
this.hasNewGroupName = !!name;
}
focus() {
this.shadowRoot?.querySelector('input')?.focus();
}
handleCreateGroup() {
const name = this._name as GroupName;
return this.restApiService.createGroup({name}).then(groupRegistered => {

View File

@@ -83,6 +83,10 @@ export class GrCreateRepoDialog extends GestureEventListeners(
return getBaseUrl() + '/admin/repos/' + encodeURL(repoName, true);
}
focus() {
this.shadowRoot?.querySelector('input')?.focus();
}
@observe('_repoConfig.name')
_updateRepoName(name: string) {
this.hasNewRepoName = !!name;

View File

@@ -169,7 +169,9 @@ export class GrRepoList extends ListViewMixin(
}
_handleCreateClicked() {
this.$.createOverlay.open();
this.$.createOverlay.open().then(() => {
this.$.createNewModal.focus();
});
}
_readOnly(repo: ProjectInfoWithName) {

View File

@@ -151,7 +151,8 @@ suite('gr-repo-list tests', () => {
});
test('_handleCreateClicked opens modal', () => {
const openStub = sinon.stub(element.$.createOverlay, 'open');
const openStub = sinon.stub(element.$.createOverlay, 'open').returns(
Promise.resolve());
element._handleCreateClicked();
assert.isTrue(openStub.called);
});