Whenever I use a textarea to enter text, I find that I have to press Shift
+ Enter
every time
to send the text. However, upon sending, it adds /n
at the end. I prefer using the Enter
key for newline instead of submitting the form.
Example: hello => hello\n
If the image is not selected, it can be sent by pressing the Enter key:
https://i.stack.imgur.com/wvRyL.png
Here is my code:
checkSubmitKey() {
if (!this.isEnterSubmit) {
this.sendMessage();
}
},
onChangeInput() {
this.getTextareaRef().addEventListener("keyup", (e) => {
this.handlesaveDraftMessages()
if (e.key === "Enter" && !e.shiftKey && this.isEnterSubmit) {
this.sendMessage();
this.resizeTextarea();
}
});
this.resizeTextarea();
},
resizeTextarea() {
const el = this.getTextareaRef();
if (!el) {
return;
}
el.style.height = "auto";
let newHeight = el.scrollHeight;
el.style.height = `${newHeight}px`;
},
<textarea
rows="1"
id="roomTextarea"
ref="roomTextarea"
v-model="messageInput"
:placeholder="$t('containers.admin.chat.chatPlaceholder')"
class="room-footer-reply-textarea"
@keyup="onChangeInput"
@keyup.enter.shift.exact.prevent="checkSubmitKey"
@click.self="checkmarkSeen"
@paste="onPasteClipboard"
/>
How can I resolve the issue mentioned above?
Thank you for your assistance!