I have Vue app and I would like to add Facebook inspired buttons in-lined in a comment form. I had plain JS prototype that was working. When I tried to incorporate it into the Vue app I faced an issue with multiple occurrences of the component on the page because it heavily used element id. I would be able to declare dynamic id but this approach was not working well because <style> is static. I found refs later and got inspired by this wonderful article: https://www.telerik.com/blogs/how-to-target-the-dom-in-vue. Long story short: my callback is never called.
Source code:
<b-form-textarea
class="textarea" ref="textareaRef"
rows="1" max-rows="8"
@oninput.native = "adjustIconsInTextarea"
:placeholder="$t('comment.write-comment-placeholder')"
v-model="text"
>
<div class="icons" ref="iconsRef">
<b-button :id="`emoji_list_${commentId}`" class="mt-2" variant="outline" size="sm">
😀
</b-button>
</div>
methods: {
adjustIconsInTextarea() {
const textComment = this.$refs.textareaRef;
console.log(textComment.value.length);
const icons = this.$refs.iconsRef;
if (textComment.value.length > 140) {
textComment.style.padding = '13px 50px 34px 32px';
icons.style.top = '-36px';
icons.style.right = '72px';
} else {
textComment.style.padding = '10px 174px 5px 28px';
icons.style.top = '-45px';
icons.style.right = '68px';
}
},
Bootstrap-vue b-form-textarea's events. Where is the error?
@input= "adjustIconsInTextarea"