11<script lang="ts">
22import {SvgIcon } from ' ../svg.ts' ;
33import {GET } from ' ../modules/fetch.ts' ;
4+ import {generateAriaId } from ' ../modules/fomantic/base.ts' ;
45
56export default {
67 components: {SvgIcon },
@@ -9,12 +10,16 @@ export default {
910 return {
1011 menuVisible: false ,
1112 isLoading: false ,
13+ queryParams: el .getAttribute (' data-queryparams' ),
14+ issueLink: el .getAttribute (' data-issuelink' ),
1215 locale: {
1316 filter_changes_by_commit: el .getAttribute (' data-filter_changes_by_commit' ),
1417 },
1518 commits: [],
1619 hoverActivated: false ,
1720 lastReviewCommitSha: null ,
21+ uniqueIdMenu: generateAriaId (),
22+ uniqueIdShowAll: generateAriaId (),
1823 };
1924 },
2025 computed: {
@@ -24,12 +29,6 @@ export default {
2429 }
2530 return 0 ;
2631 },
27- queryParams() {
28- return this .$el .parentNode .getAttribute (' data-queryparams' );
29- },
30- issueLink() {
31- return this .$el .parentNode .getAttribute (' data-issuelink' );
32- },
3332 },
3433 mounted() {
3534 document .body .addEventListener (' click' , this .onBodyClick );
@@ -68,6 +67,11 @@ export default {
6867 this .toggleMenu ();
6968 break ;
7069 }
70+ if (event .key === ' ArrowDown' || event .key === ' ArrowUp' ) {
71+ const item = document .activeElement ; // try to highlight the selected commits
72+ const commitIdx = item ?.matches (' .item' ) ? item .getAttribute (' data-commit-idx' ) : null ;
73+ if (commitIdx ) this .highlight (this .commits [commitIdx ]);
74+ }
7175 },
7276 onKeyUp(event ) {
7377 if (! this .menuVisible ) return ;
@@ -113,12 +117,10 @@ export default {
113117 }
114118 // set correct tabindex to allow easier navigation
115119 this .$nextTick (() => {
116- const expandBtn = this .$el .querySelector (' #diff-commit-list-expand' );
117- const showAllChanges = this .$el .querySelector (' #diff-commit-list-show-all' );
118120 if (this .menuVisible ) {
119- this .focusElem (showAllChanges , expandBtn );
121+ this .focusElem (this . $refs . showAllChanges , this . $refs . expandBtn );
120122 } else {
121- this .focusElem (expandBtn , showAllChanges );
123+ this .focusElem (this . $refs . expandBtn , this . $refs . showAllChanges );
122124 }
123125 });
124126 },
@@ -189,22 +191,23 @@ export default {
189191};
190192 </script >
191193<template >
192- <div class =" ui scrolling dropdown custom" >
194+ <div class =" ui scrolling dropdown custom diff-commit-selector " >
193195 <button
196+ ref =" expandBtn"
194197 class =" ui basic button"
195- id =" diff-commit-list-expand"
196198 @click.stop =" toggleMenu()"
197199 :data-tooltip-content =" locale.filter_changes_by_commit"
198200 aria-haspopup =" true"
199- aria-controls =" diff-commit-selector-menu"
200201 :aria-label =" locale.filter_changes_by_commit"
201- aria-activedescendant =" diff-commit-list-show-all"
202+ :aria-controls =" uniqueIdMenu"
203+ :aria-activedescendant =" uniqueIdShowAll"
202204 >
203205 <svg-icon name =" octicon-git-commit" />
204206 </button >
205- <div class =" left menu" id =" diff-commit-selector-menu" :class =" {visible: menuVisible}" v-show =" menuVisible" v-cloak :aria-expanded =" menuVisible ? 'true': 'false'" >
207+ <!-- this dropdown is not managed by Fomantic UI, so it needs some classes like "transition" explicitly -->
208+ <div class =" left menu transition" :id =" uniqueIdMenu" :class =" {visible: menuVisible}" v-show =" menuVisible" v-cloak :aria-expanded =" menuVisible ? 'true': 'false'" >
206209 <div class =" loading-indicator is-loading" v-if =" isLoading" />
207- <div v-if =" !isLoading" class =" vertical item" id =" diff-commit-list-show-all " role =" menuitem" @keydown.enter =" showAllChanges()" @click =" showAllChanges()" >
210+ <div v-if =" !isLoading" class =" item" : id =" uniqueIdShowAll " ref = " showAllChanges " role =" menuitem" @keydown.enter =" showAllChanges()" @click =" showAllChanges()" >
208211 <div class =" gt-ellipsis" >
209212 {{ locale.show_all_commits }}
210213 </div >
@@ -214,8 +217,8 @@ export default {
214217 </div >
215218 <!-- only show the show changes since last review if there is a review AND we are commits ahead of the last review -->
216219 <div
217- v-if =" lastReviewCommitSha != null" role = " menuitem "
218- class =" vertical item"
220+ v-if =" lastReviewCommitSha != null"
221+ class =" item" role = " menuitem "
219222 :class =" {disabled: !commitsSinceLastReview}"
220223 @keydown.enter =" changesSinceLastReviewClick()"
221224 @click =" changesSinceLastReviewClick()"
@@ -228,10 +231,11 @@ export default {
228231 </div >
229232 </div >
230233 <span v-if =" !isLoading" class =" info text light-2" >{{ locale.select_commit_hold_shift_for_range }}</span >
231- <template v-for =" commit in commits " :key =" commit .id " >
234+ <template v-for =" ( commit , idx ) in commits " :key =" commit .id " >
232235 <div
233- class =" vertical item" role =" menuitem"
234- :class =" {selection: commit.selected, hovered: commit.hovered}"
236+ class =" item" role =" menuitem"
237+ :class =" {selected: commit.selected, hovered: commit.hovered}"
238+ :data-commit-idx =" idx"
235239 @keydown.enter.exact =" commitClicked(commit.id)"
236240 @keydown.enter.shift.exact =" commitClickedShift(commit)"
237241 @mouseover.shift =" highlight(commit)"
@@ -261,46 +265,44 @@ export default {
261265 </div >
262266</template >
263267<style scoped>
264- .hovered :not (.selection ) {
265- background-color : var (--color-small-accent ) !important ;
266- }
267- .selection {
268- background-color : var (--color-accent ) !important ;
269- }
270-
271- .info {
272- display : inline-block ;
273- padding : 7px 14px !important ;
274- line-height : 1.4 ;
275- width : 100% ;
276- }
277-
278- #diff-commit-selector-menu {
268+ .ui.dropdown.diff-commit-selector .menu {
269+ margin-top : 0.25em ;
279270 overflow-x : hidden ;
280271 max-height : 450px ;
281272 }
282273
283- # diff-commit-selector- menu .loading-indicator {
274+ .ui.dropdown. diff-commit-selector . menu .loading-indicator {
284275 height : 200px ;
285276 width : 350px ;
286277 }
287278
288- # diff-commit-selector- menu .item ,
289- # diff-commit-selector- menu .info {
290- display : flex !important ;
279+ .ui.dropdown. diff-commit-selector . menu > .item ,
280+ .ui.dropdown. diff-commit-selector . menu > .info {
281+ display : flex ;
291282 flex-direction : row ;
292283 line-height : 1.4 ;
284+ gap : 0.25em ;
293285 padding : 7px 14px !important ;
286+ }
287+
288+ .ui.dropdown.diff-commit-selector .menu > .item :not (:first-child ),
289+ .ui.dropdown.diff-commit-selector .menu > .info :not (:first-child ) {
294290 border-top : 1px solid var (--color-secondary ) !important ;
295- gap : 0.25em ;
296291 }
297292
298- #diff-commit-selector-menu .item :focus {
299- color : var (--color-text );
300- background : var (--color-hover );
293+ .ui.dropdown.diff-commit-selector .menu > .item :focus {
294+ background : var (--color-active );
295+ }
296+
297+ .ui.dropdown.diff-commit-selector .menu > .item.hovered {
298+ background-color : var (--color-small-accent );
299+ }
300+
301+ .ui.dropdown.diff-commit-selector .menu > .item.selected {
302+ background-color : var (--color-accent );
301303 }
302304
303- # diff-commit-selector- menu .commit-list-summary {
305+ .ui.dropdown. diff-commit-selector . menu .commit-list-summary {
304306 max-width : min (380px , 96vw );
305307 }
306308 </style >
0 commit comments