Skip to content

Commit b6d8d69

Browse files
Add up and down arrows to selected lookup repositories (#24727)
Use up and down arrow key to select repositories ![image](https://github.com/go-gitea/gitea/assets/1255041/3f3bce64-86d9-4b37-994b-3d129ebf48d9) --------- Co-authored-by: silverwind <[email protected]>
1 parent 72eedfb commit b6d8d69

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

web_src/js/components/DashboardRepoList.vue

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</h4>
1818
<div class="ui attached segment repos-search">
1919
<div class="ui fluid right action left icon input" :class="{loading: isLoading}">
20-
<input @input="changeReposFilter(reposFilter)" v-model="searchQuery" ref="search" :placeholder="textSearchRepos">
20+
<input @input="changeReposFilter(reposFilter)" v-model="searchQuery" ref="search" @keydown="reposFilterKeyControl" :placeholder="textSearchRepos">
2121
<i class="icon gt-df gt-ac gt-jc"><svg-icon name="octicon-search" :size="16"/></i>
2222
<div class="ui dropdown icon button" :title="textFilter">
2323
<i class="icon gt-df gt-ac gt-jc gt-m-0"><svg-icon name="octicon-filter" :size="16"/></i>
@@ -70,7 +70,7 @@
7070
</div>
7171
<div v-if="repos.length" class="ui attached table segment gt-rounded-bottom">
7272
<ul class="repo-owner-name-list">
73-
<li class="gt-df gt-ac" v-for="repo in repos" :key="repo.id">
73+
<li class="gt-df gt-ac" v-for="repo, index in repos" :class="{'active': index === activeIndex}" :key="repo.id">
7474
<a class="repo-list-link muted gt-df gt-ac gt-f1" :href="repo.link">
7575
<svg-icon :name="repoIcon(repo)" :size="16" class-name="repo-list-icon"/>
7676
<div class="text truncate">{{ repo.full_name }}</div>
@@ -215,6 +215,7 @@ const sfc = {
215215
216216
subUrl: appSubUrl,
217217
...pageData.dashboardRepoList,
218+
activeIndex: -1, // don't select anything at load, first cursor down will select
218219
};
219220
},
220221
@@ -429,6 +430,43 @@ const sfc = {
429430
430431
statusColor(status) {
431432
return commitStatus[status].color;
433+
},
434+
435+
reposFilterKeyControl(e) {
436+
switch (e.key) {
437+
case 'Enter':
438+
document.querySelector('.repo-owner-name-list li.active a')?.click();
439+
break;
440+
case 'ArrowUp':
441+
if (this.activeIndex > 0) {
442+
this.activeIndex--;
443+
} else if (this.page > 1) {
444+
this.changePage(this.page - 1);
445+
this.activeIndex = this.searchLimit - 1;
446+
}
447+
break;
448+
case 'ArrowDown':
449+
if (this.activeIndex < this.repos.length - 1) {
450+
this.activeIndex++;
451+
} else if (this.page < this.finalPage) {
452+
this.activeIndex = 0;
453+
this.changePage(this.page + 1);
454+
}
455+
break;
456+
case 'ArrowRight':
457+
if (this.page < this.finalPage) {
458+
this.changePage(this.page + 1);
459+
}
460+
break;
461+
case 'ArrowLeft':
462+
if (this.page > 1) {
463+
this.changePage(this.page - 1);
464+
}
465+
break;
466+
}
467+
if (this.activeIndex === -1 || this.activeIndex > this.repos.length - 1) {
468+
this.activeIndex = 0;
469+
}
432470
}
433471
},
434472
};
@@ -480,4 +518,8 @@ ul li:not(:last-child) {
480518
margin-left: 1px;
481519
margin-right: 3px;
482520
}
521+
522+
.repo-owner-name-list li.active {
523+
background: var(--color-hover);
524+
}
483525
</style>

0 commit comments

Comments
 (0)