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

Commit 0ceef55

Browse files
committed
feat: add mouse support with keyboard continuity
1 parent b509f19 commit 0ceef55

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/components/App.vue

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
<div class="flags-dropdown-arrow" />
77
<RegionInput
88
:value="value"
9-
@input="onInput($event)"
9+
@input="onInput"
1010
@up="onUp"
1111
@down="onDown"
12-
@enter="onEnter"
12+
@enter="onSelectRegion"
1313
@reset="onReset"
1414
/>
1515
<RegionsList
1616
:regions="filteredRegions"
1717
:filter="value"
1818
:highlighted-index="highlightedIndex"
19-
:selected-region="selectedRegion"
19+
:selected="selectedRegion"
20+
@highlight="onHighlightRegion"
21+
@select="onSelectRegion"
2022
/>
2123
<a
2224
:href="moreParameters.href"
@@ -72,11 +74,14 @@ export default {
7274
this.highlightedIndex += 1;
7375
}
7476
},
75-
onInput(event) {
76-
this.value = event;
77+
onHighlightRegion(region) {
78+
this.highlightedIndex = this.filteredRegions.findIndex(reg => reg.name === region.name);
79+
},
80+
onInput(value) {
81+
this.value = value;
7782
this.highlightedIndex = 0;
7883
},
79-
onEnter() {
84+
onSelectRegion() {
8085
const updatedCookieString = this.cookieString
8186
.split(':')
8287
.map((paramString) => {

src/components/RegionItem.vue

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<li
33
:data-selected="region.locale"
44
:class="{ [$style.highlighted]: highlighted }"
5+
@mouseenter="$emit('highlight', region)"
6+
@click="$emit('select')"
57
>
68
<span :class="`flag ${country}`" />
79
{{ region.name }}

src/components/RegionsList.vue

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<template>
22
<div class="flags-dropdown-body">
33
<p class="flags-dropdown-chosen js-select-chosen">
4-
<span :class="selectedRegion.class" />
5-
<strong class="js-selected-text">{{ selectedRegion.name }}</strong>
4+
<span :class="selected.class" />
5+
<strong class="js-selected-text">{{ selected.name }}</strong>
66
</p>
77
<ul class="flags-dropdown-list">
88
<RegionItem
99
v-for="(region, index) in regions"
1010
:key="region.id"
1111
:region="region"
1212
:highlighted="index === highlightedIndex"
13+
@highlight="highlight"
14+
@select="$emit('select')"
1315
/>
1416
</ul>
1517
</div>
@@ -27,7 +29,12 @@ export default {
2729
regions: { type: Object, required: true },
2830
filter: { type: String, required: true },
2931
highlightedIndex: { type: Number, required: true },
30-
selectedRegion: { type: Object, default: () => ({}) },
32+
selected: { type: Object, default: () => ({}) },
33+
},
34+
methods: {
35+
highlight(region) {
36+
this.$emit('highlight', region);
37+
},
3138
},
3239
};
3340
</script>

0 commit comments

Comments
 (0)