From 47921bca3de4d1bb7e0a0c38cc58d0a98e8266af Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 20 Sep 2023 12:51:00 +0530 Subject: [PATCH] fix: safer access to textarea --- app/javascript/shared/components/ResizableTextArea.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/javascript/shared/components/ResizableTextArea.vue b/app/javascript/shared/components/ResizableTextArea.vue index bc7c89dc0..083632858 100644 --- a/app/javascript/shared/components/ResizableTextArea.vue +++ b/app/javascript/shared/components/ResizableTextArea.vue @@ -113,7 +113,6 @@ export default { }); }, setCursor() { - const textarea = this.$refs.textarea; const bodyWithoutSignature = removeSignature( this.value, this.cleanedSignature @@ -121,9 +120,12 @@ export default { // only trim at end, so if there are spaces at the start, those are not removed const bodyEndsAt = bodyWithoutSignature.trimEnd().length; + const textarea = this.$refs.textarea; - textarea.focus(); - textarea.setSelectionRange(bodyEndsAt, bodyEndsAt); + if (textarea) { + textarea.focus(); + textarea.setSelectionRange(bodyEndsAt, bodyEndsAt); + } }, onInput(event) { this.$emit('input', event.target.value);