Skip to content

Commit dc064f2

Browse files
committed
improved tag-input to handle backspace better
1 parent 5104951 commit dc064f2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/components/tag-input.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ export default class TagInput extends LitElement {
44
/* eslint-disable indent */
55
render() {
66
return html`
7-
<div class='tags' tabindex="0" contenteditable="true">
7+
<div class='tags' tabindex="0">
88
${Array.isArray(this.value) && this.value.length > 0
9-
? html`${this.value.map((v) => html`
10-
<span contenteditable="false" class='tag'> ${v} </span>
11-
`)}`
9+
? html`${this.value.map((v) => html`<span class='tag'> ${v} </span>`)}`
1210
: ''
1311
}
1412
<input type="text" class='editor' @paste="${this.afterPaste}" @keydown="${this.afterKeyDown}" placeholder="${this.placeholder}">
@@ -43,9 +41,11 @@ export default class TagInput extends LitElement {
4341
e.target.value = '';
4442
}
4543
} else if (e.keyCode === 8) {
46-
if (Array.isArray(this.value) && this.value.length > 0) {
47-
this.value.splice(-1);
48-
this.value = [...this.value];
44+
if (e.target.value.length === 0) {
45+
if (Array.isArray(this.value) && this.value.length > 0) {
46+
this.value.splice(-1);
47+
this.value = [...this.value];
48+
}
4949
}
5050
}
5151
}
@@ -73,7 +73,7 @@ export default class TagInput extends LitElement {
7373
color:var(--fg3);
7474
border-radius:var(--border-radius);
7575
word-break: break-all;
76-
font-size: calc(var(--font-size-small) + 1px);
76+
font-size: var(--font-size-small);
7777
}
7878
.tag:hover ~ #cursor {
7979
display: block;

0 commit comments

Comments
 (0)