Skip to content

Commit 67a1fc1

Browse files
committed
(chore) add getTextareaRef method
1 parent 7ed8c3a commit 67a1fc1

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/lib/Room/Room.vue

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export default {
481481
482482
watch: {
483483
message(val) {
484-
this.$refs.roomTextarea.value = val
484+
this.getTextareaRef().value = val
485485
},
486486
loadingMessages(val) {
487487
if (val) {
@@ -539,7 +539,7 @@ export default {
539539
this.newMessages = []
540540
const isMobile = detectMobile()
541541
542-
this.$refs.roomTextarea.addEventListener(
542+
this.getTextareaRef().addEventListener(
543543
'keyup',
544544
debounce(e => {
545545
if (e.key === 'Enter' && !e.shiftKey && !this.fileDialog) {
@@ -564,15 +564,15 @@ export default {
564564
50
565565
)
566566
567-
this.$refs.roomTextarea.addEventListener('click', () => {
567+
this.getTextareaRef().addEventListener('click', () => {
568568
if (isMobile) this.keepKeyboardOpen = true
569569
570570
this.updateFooterList('@')
571571
this.updateFooterList(':')
572572
this.updateFooterList('/')
573573
})
574574
575-
this.$refs.roomTextarea.addEventListener('blur', () => {
575+
this.getTextareaRef().addEventListener('blur', () => {
576576
this.resetFooterList()
577577
if (isMobile) setTimeout(() => (this.keepKeyboardOpen = false))
578578
})
@@ -583,6 +583,9 @@ export default {
583583
},
584584
585585
methods: {
586+
getTextareaRef() {
587+
return this.$refs.roomTextarea.$refs.roomTextarea
588+
},
586589
touchStart(touchEvent) {
587590
if (this.singleRoom) return
588591
@@ -672,7 +675,7 @@ export default {
672675
this.scrollIcon = bottomScroll > 500 || this.scrollMessagesCount
673676
},
674677
updateFooterList(tagChar) {
675-
if (!this.$refs.roomTextarea) return
678+
if (!this.getTextareaRef()) return
676679
677680
if (
678681
tagChar === '@' &&
@@ -686,12 +689,12 @@ export default {
686689
}
687690
688691
if (
689-
this.textareaCursorPosition === this.$refs.roomTextarea.selectionStart
692+
this.textareaCursorPosition === this.getTextareaRef().selectionStart
690693
) {
691694
return
692695
}
693696
694-
this.textareaCursorPosition = this.$refs.roomTextarea.selectionStart
697+
this.textareaCursorPosition = this.getTextareaRef().selectionStart
695698
696699
let position = this.textareaCursorPosition
697700
@@ -726,7 +729,7 @@ export default {
726729
}
727730
},
728731
getCharPosition(tagChar) {
729-
const cursorPosition = this.$refs.roomTextarea.selectionStart
732+
const cursorPosition = this.getTextareaRef().selectionStart
730733
731734
let position = cursorPosition
732735
while (position > 0 && this.message.charAt(position - 1) !== tagChar) {
@@ -885,17 +888,18 @@ export default {
885888
setTimeout(() => this.focusTextarea(disableMobileFocus))
886889
},
887890
resetTextareaSize() {
888-
if (!this.$refs.roomTextarea) return
889-
this.$refs.roomTextarea.style.height = '20px'
891+
if (this.getTextareaRef()) {
892+
this.getTextareaRef().style.height = '20px'
893+
}
890894
},
891895
focusTextarea(disableMobileFocus) {
892896
if (detectMobile() && disableMobileFocus) return
893-
if (!this.$refs.roomTextarea) return
894-
this.$refs.roomTextarea.focus()
897+
if (!this.getTextareaRef()) return
898+
this.getTextareaRef().focus()
895899
896900
if (this.cursorRangePosition) {
897901
setTimeout(() => {
898-
this.$refs.roomTextarea.setSelectionRange(
902+
this.getTextareaRef().setSelectionRange(
899903
this.cursorRangePosition,
900904
this.cursorRangePosition
901905
)
@@ -904,7 +908,7 @@ export default {
904908
}
905909
},
906910
preventKeyboardFromClosing() {
907-
if (this.keepKeyboardOpen) this.$refs.roomTextarea.focus()
911+
if (this.keepKeyboardOpen) this.getTextareaRef().focus()
908912
},
909913
sendMessage() {
910914
let message = this.message.trim()
@@ -1045,7 +1049,7 @@ export default {
10451049
this.$emit('typing-message', this.message)
10461050
}, 100),
10471051
resizeTextarea() {
1048-
const el = this.$refs.roomTextarea
1052+
const el = this.getTextareaRef()
10491053
10501054
if (!el) return
10511055

0 commit comments

Comments
 (0)