Skip to content

Commit e64c2cb

Browse files
authored
Merge pull request #623 from jens1o/jens1o/seamless-tag-input
Make adding tags more user-friendly
2 parents f511864 + d69e30b commit e64c2cb

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/components/profile/edit/EditTags.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535
>
3636
</Tag>
3737
</div>
38+
<!-- add new tag when pressing either the enter or the comma key (keyCode: 188) -->
3839
<input
3940
v-if="addingTag"
4041
type="text"
4142
v-model="newTag"
4243
ref="inputTag"
4344
class="add-tags__input"
4445
@keydown.enter="handleAddTag"
46+
@keydown.188.prevent="handleAddTag"
47+
@paste="handlePaste"
4548
/>
4649
<button
4750
type="button"
@@ -95,7 +98,6 @@ export default {
9598
}
9699
if (this.newTag.length > 0) {
97100
this.addTag(this.newTag);
98-
this.addingTag = false;
99101
} else {
100102
this.$refs.inputTag.focus();
101103
}
@@ -118,6 +120,19 @@ export default {
118120
this.tags.values.splice(index, 1);
119121
}
120122
},
123+
handlePaste() {
124+
this.$nextTick(() => {
125+
let text = this.$refs.inputTag.value;
126+
127+
if (text === '' || !text.includes(',')) {
128+
return;
129+
}
130+
131+
for (let tag of text.split(',')) {
132+
this.addTag(tag.trim());
133+
}
134+
});
135+
},
121136
},
122137
mounted() {
123138
this.$refs.header.focus();

0 commit comments

Comments
 (0)