Skip to content
This repository was archived by the owner on Jun 13, 2021. It is now read-only.

Commit d7ddecd

Browse files
committed
feat: add scrolling on keyboard navigation
Remove mouse / keyboard continuity to favour maintainability over unsual use cases
1 parent 0ceef55 commit d7ddecd

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/components/App.vue

-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
:filter="value"
1818
:highlighted-index="highlightedIndex"
1919
:selected="selectedRegion"
20-
@highlight="onHighlightRegion"
2120
@select="onSelectRegion"
2221
/>
2322
<a
@@ -74,9 +73,6 @@ export default {
7473
this.highlightedIndex += 1;
7574
}
7675
},
77-
onHighlightRegion(region) {
78-
this.highlightedIndex = this.filteredRegions.findIndex(reg => reg.name === region.name);
79-
},
8076
onInput(value) {
8177
this.value = value;
8278
this.highlightedIndex = 0;

src/components/RegionItem.vue

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template>
22
<li
33
:data-selected="region.locale"
4-
:class="{ [$style.highlighted]: highlighted }"
5-
@mouseenter="$emit('highlight', region)"
4+
:class="[$style.item, { [$style.highlighted]: highlighted }]"
65
@click="$emit('select')"
76
>
87
<span :class="`flag ${country}`" />
@@ -26,7 +25,11 @@ export default {
2625
</script>
2726

2827
<style module>
29-
.highlighted {
30-
background-color: lightblue;
28+
.highlighted,
29+
.item:hover {
30+
background-color: rgb(237, 237, 237);
31+
}
32+
.highlighted.item:hover {
33+
background-color: rgb(224, 224, 224);
3134
}
3235
</style>

src/components/RegionsList.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
<span :class="selected.class" />
55
<strong class="js-selected-text">{{ selected.name }}</strong>
66
</p>
7-
<ul class="flags-dropdown-list">
7+
<ul
8+
ref="regionItems"
9+
class="flags-dropdown-list"
10+
>
811
<RegionItem
912
v-for="(region, index) in regions"
1013
:key="region.id"
1114
:region="region"
1215
:highlighted="index === highlightedIndex"
13-
@highlight="highlight"
1416
@select="$emit('select')"
1517
/>
1618
</ul>
@@ -31,10 +33,13 @@ export default {
3133
highlightedIndex: { type: Number, required: true },
3234
selected: { type: Object, default: () => ({}) },
3335
},
34-
methods: {
35-
highlight(region) {
36-
this.$emit('highlight', region);
36+
computed: {
37+
listItemHeight() {
38+
return this.$refs.regionItems.querySelector('li').clientHeight;
3739
},
3840
},
41+
beforeUpdate() {
42+
this.$refs.regionItems.scrollTop = this.listItemHeight * this.highlightedIndex;
43+
},
3944
};
4045
</script>

0 commit comments

Comments
 (0)