#101 - update caret pos after emoji's inserted

This commit is contained in:
jared 2019-04-08 11:10:26 -04:00
parent b4e53576f2
commit 820a6543c7
3 changed files with 22 additions and 1 deletions

View file

@ -110,6 +110,25 @@ const EmojiInput = {
const newValue = this.value.substr(0, this.caret) + emoji + this.value.substr(this.caret)
this.$refs.input.focus()
this.$emit('input', newValue)
this.caret += emoji.length
setTimeout(() => {
this.updateCaretPos()
})
},
updateCaretPos () {
const elem = this.$refs.input
if (elem.createTextRange) {
const range = elem.createTextRange()
range.move('character', this.caret)
range.select()
} else {
if (elem.selectionStart) {
elem.focus()
elem.setSelectionRange(this.caret, this.caret)
} else {
elem.focus()
}
}
}
}
}

View file

@ -6,6 +6,7 @@
:type="type"
:value="value"
:placeholder="placeholder"
id="good"
@input="onInput"
@click="setCaret"
@keyup="setCaret"

View file

@ -42,7 +42,7 @@
&-dropdown {
position: absolute;
right: 0;
top: 100%;
top: 28px;
z-index: 1;
&-toggle {
@ -50,6 +50,7 @@
position: absolute;
top: -25px;
right: 2px;
line-height: 1;
i {
font-size: 18px;