I want to use contenteditable
attribute of HTML for my component to make a area editable.
For this, I use @input directive but it does not work as I expect. I expect the caret keeps the end of the entire input value but it moves to the head position.
Animation Gif Image
Demo
https://codesandbox.io/s/oj9p82kvp6
Code
<template>
<div>
<p contenteditable="true" @input="update">{{ text }}</p>
</div>
</template>
<script>
export default {
name: 'ReadWrite',
data () {
return {
text: 'edit here!'
}
},
methods: {
update (e) {
this.text = e.target.textContent
}
}
}
</script>
<style scoped>
:read-write {
border: solid 1px #cccccc;
padding: 5px;
}
</style>