1
1
<script lang="ts">
2
2
import {SvgIcon } from ' ../svg.ts' ;
3
3
import {GET } from ' ../modules/fetch.ts' ;
4
+ import {generateAriaId } from ' ../modules/fomantic/base.ts' ;
4
5
5
6
export default {
6
7
components: {SvgIcon },
@@ -9,12 +10,16 @@ export default {
9
10
return {
10
11
menuVisible: false ,
11
12
isLoading: false ,
13
+ queryParams: el .getAttribute (' data-queryparams' ),
14
+ issueLink: el .getAttribute (' data-issuelink' ),
12
15
locale: {
13
16
filter_changes_by_commit: el .getAttribute (' data-filter_changes_by_commit' ),
14
17
},
15
18
commits: [],
16
19
hoverActivated: false ,
17
20
lastReviewCommitSha: null ,
21
+ uniqueIdMenu: generateAriaId (),
22
+ uniqueIdShowAll: generateAriaId (),
18
23
};
19
24
},
20
25
computed: {
@@ -24,12 +29,6 @@ export default {
24
29
}
25
30
return 0 ;
26
31
},
27
- queryParams() {
28
- return this .$el .parentNode .getAttribute (' data-queryparams' );
29
- },
30
- issueLink() {
31
- return this .$el .parentNode .getAttribute (' data-issuelink' );
32
- },
33
32
},
34
33
mounted() {
35
34
document .body .addEventListener (' click' , this .onBodyClick );
@@ -68,6 +67,11 @@ export default {
68
67
this .toggleMenu ();
69
68
break ;
70
69
}
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
+ }
71
75
},
72
76
onKeyUp(event ) {
73
77
if (! this .menuVisible ) return ;
@@ -113,12 +117,10 @@ export default {
113
117
}
114
118
// set correct tabindex to allow easier navigation
115
119
this .$nextTick (() => {
116
- const expandBtn = this .$el .querySelector (' #diff-commit-list-expand' );
117
- const showAllChanges = this .$el .querySelector (' #diff-commit-list-show-all' );
118
120
if (this .menuVisible ) {
119
- this .focusElem (showAllChanges , expandBtn );
121
+ this .focusElem (this . $refs . showAllChanges , this . $refs . expandBtn );
120
122
} else {
121
- this .focusElem (expandBtn , showAllChanges );
123
+ this .focusElem (this . $refs . expandBtn , this . $refs . showAllChanges );
122
124
}
123
125
});
124
126
},
@@ -189,22 +191,23 @@ export default {
189
191
};
190
192
</script >
191
193
<template >
192
- <div class =" ui scrolling dropdown custom" >
194
+ <div class =" ui scrolling dropdown custom diff-commit-selector " >
193
195
<button
196
+ ref =" expandBtn"
194
197
class =" ui basic button"
195
- id =" diff-commit-list-expand"
196
198
@click.stop =" toggleMenu()"
197
199
:data-tooltip-content =" locale.filter_changes_by_commit"
198
200
aria-haspopup =" true"
199
- aria-controls =" diff-commit-selector-menu"
200
201
:aria-label =" locale.filter_changes_by_commit"
201
- aria-activedescendant =" diff-commit-list-show-all"
202
+ :aria-controls =" uniqueIdMenu"
203
+ :aria-activedescendant =" uniqueIdShowAll"
202
204
>
203
205
<svg-icon name =" octicon-git-commit" />
204
206
</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'" >
206
209
<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()" >
208
211
<div class =" gt-ellipsis" >
209
212
{{ locale.show_all_commits }}
210
213
</div >
@@ -214,8 +217,8 @@ export default {
214
217
</div >
215
218
<!-- only show the show changes since last review if there is a review AND we are commits ahead of the last review -->
216
219
<div
217
- v-if =" lastReviewCommitSha != null" role = " menuitem "
218
- class =" vertical item"
220
+ v-if =" lastReviewCommitSha != null"
221
+ class =" item" role = " menuitem "
219
222
:class =" {disabled: !commitsSinceLastReview}"
220
223
@keydown.enter =" changesSinceLastReviewClick()"
221
224
@click =" changesSinceLastReviewClick()"
@@ -228,10 +231,11 @@ export default {
228
231
</div >
229
232
</div >
230
233
<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 " >
232
235
<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"
235
239
@keydown.enter.exact =" commitClicked(commit.id)"
236
240
@keydown.enter.shift.exact =" commitClickedShift(commit)"
237
241
@mouseover.shift =" highlight(commit)"
@@ -261,46 +265,44 @@ export default {
261
265
</div >
262
266
</template >
263
267
<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 ;
279
270
overflow-x : hidden ;
280
271
max-height : 450px ;
281
272
}
282
273
283
- # diff-commit-selector- menu .loading-indicator {
274
+ .ui.dropdown. diff-commit-selector . menu .loading-indicator {
284
275
height : 200px ;
285
276
width : 350px ;
286
277
}
287
278
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 ;
291
282
flex-direction : row ;
292
283
line-height : 1.4 ;
284
+ gap : 0.25em ;
293
285
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 ) {
294
290
border-top : 1px solid var (--color-secondary ) !important ;
295
- gap : 0.25em ;
296
291
}
297
292
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 );
301
303
}
302
304
303
- # diff-commit-selector- menu .commit-list-summary {
305
+ .ui.dropdown. diff-commit-selector . menu .commit-list-summary {
304
306
max-width : min (380px , 96vw );
305
307
}
306
308
</style >
0 commit comments