diff options
Diffstat (limited to 'viewer/src/components')
-rw-r--r-- | viewer/src/components/LdTagInput.vue | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/viewer/src/components/LdTagInput.vue b/viewer/src/components/LdTagInput.vue index 865db96..6b6e749 100644 --- a/viewer/src/components/LdTagInput.vue +++ b/viewer/src/components/LdTagInput.vue | |||
@@ -30,7 +30,9 @@ | |||
30 | size="is-medium" | 30 | size="is-medium" |
31 | class="paneltag-input" | 31 | class="paneltag-input" |
32 | @typing="searchTags" | 32 | @typing="searchTags" |
33 | @click.capture.native="onClick" | 33 | @add="clearCurrentFilter" |
34 | @remove="clearCurrentFilter" | ||
35 | @keydown.enter.native="onKeyEnter" | ||
34 | > | 36 | > |
35 | <template slot-scope="props">{{displayOption(props.option)}}</template> | 37 | <template slot-scope="props">{{displayOption(props.option)}}</template> |
36 | <template slot="empty">{{$t('tagInput.nomatch')}}</template> | 38 | <template slot="empty">{{$t('tagInput.nomatch')}}</template> |
@@ -38,7 +40,7 @@ | |||
38 | </template> | 40 | </template> |
39 | 41 | ||
40 | <script lang="ts"> | 42 | <script lang="ts"> |
41 | import { Component, Vue, Prop, PropSync } from "vue-property-decorator"; | 43 | import { Component, Vue, Prop, PropSync, Emit } from "vue-property-decorator"; |
42 | import { Operation } from "@/@types/Operation"; | 44 | import { Operation } from "@/@types/Operation"; |
43 | import Navigation from "@/services/navigation"; | 45 | import Navigation from "@/services/navigation"; |
44 | import IndexFactory from "@/services/indexfactory"; | 46 | import IndexFactory from "@/services/indexfactory"; |
@@ -48,6 +50,7 @@ export default class LdTagInput extends Vue { | |||
48 | @Prop({ required: true }) readonly tagsIndex!: Tag.Index; | 50 | @Prop({ required: true }) readonly tagsIndex!: Tag.Index; |
49 | @PropSync("searchFilters", { type: Array, required: true }) model!: Tag.Search[]; | 51 | @PropSync("searchFilters", { type: Array, required: true }) model!: Tag.Search[]; |
50 | 52 | ||
53 | currentFilter: string = ""; | ||
51 | filteredTags: Tag.Search[] = []; | 54 | filteredTags: Tag.Search[] = []; |
52 | 55 | ||
53 | displayOption(option: Tag.Search): string { | 56 | displayOption(option: Tag.Search): string { |
@@ -62,15 +65,27 @@ export default class LdTagInput extends Vue { | |||
62 | } | 65 | } |
63 | 66 | ||
64 | searchTags(filter: string) { | 67 | searchTags(filter: string) { |
68 | this.currentFilter = filter; | ||
65 | this.filteredTags = IndexFactory.searchTags(this.tagsIndex, filter, false) | 69 | this.filteredTags = IndexFactory.searchTags(this.tagsIndex, filter, false) |
66 | .filter(this.filterAlreadyPresent) | 70 | .filter(this.filterAlreadyPresent) |
67 | .sort((a, b) => b.items.length - a.items.length); | 71 | .sort((a, b) => b.items.length - a.items.length); |
68 | } | 72 | } |
69 | 73 | ||
70 | // Prevents the keyboard from opening on mobile when removing a tag | 74 | clearCurrentFilter() { |
71 | onClick(e: MouseEvent) { | 75 | // Necessary for @keydown.enter.native, nexttick is too short |
72 | const target = e.target; | 76 | setTimeout(() => { |
73 | if (target instanceof HTMLAnchorElement) target.addEventListener("click", e => e.stopPropagation(), true); | 77 | this.currentFilter = ""; |
78 | this.filteredTags = []; | ||
79 | }); | ||
80 | } | ||
81 | |||
82 | onKeyEnter(e: KeyboardEvent) { | ||
83 | if (!this.currentFilter) this.onkeyenterEmpty(e); | ||
84 | } | ||
85 | |||
86 | @Emit() | ||
87 | onkeyenterEmpty(e: KeyboardEvent) { | ||
88 | return e; | ||
74 | } | 89 | } |
75 | } | 90 | } |
76 | </script> | 91 | </script> |