Skip to content

Commit 8a15623

Browse files
committed
(fix) improve textarea height & focus
1 parent 44913f3 commit 8a15623

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/ChatWindow/MessagesList.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export default {
191191
watch: {
192192
loadingMessages(val) {
193193
if (val) this.infiniteState = null
194-
else this.$refs['roomTextarea'].focus()
194+
else this.focusTextarea()
195195
},
196196
room() {
197197
this.loadingMessages = true
@@ -235,13 +235,19 @@ export default {
235235
236236
methods: {
237237
resetMessage() {
238-
this.$refs['roomTextarea'].style.height = '38px'
238+
this.resetTextareaSize()
239239
this.message = ''
240240
this.editedMessage = {}
241241
this.file = null
242242
this.imageFile = null
243243
this.emojiOpened = false
244244
},
245+
resetTextareaSize() {
246+
this.$refs['roomTextarea'].style.height = '38px'
247+
},
248+
focusTextarea() {
249+
this.$refs['roomTextarea'].focus()
250+
},
245251
isMessageEmpty() {
246252
return !this.file && !this.message.trim()
247253
},
@@ -271,7 +277,7 @@ export default {
271277
},
272278
editMessage(message) {
273279
this.resetFile()
274-
this.$refs['roomTextarea'].focus()
280+
this.focusTextarea()
275281
this.editedMessage = { ...message }
276282
this.file = message.file
277283
if (this.isImageCheck(this.file)) this.imageFile = message.file.url
@@ -291,7 +297,7 @@ export default {
291297
},
292298
addEmoji(emoji) {
293299
this.message += emoji
294-
this.$refs['roomTextarea'].focus()
300+
this.focusTextarea()
295301
},
296302
launchFilePicker() {
297303
this.$refs.file.value = ''
@@ -317,12 +323,15 @@ export default {
317323
this.imageFile = null
318324
this.editedMessage.file = null
319325
this.file = null
326+
this.focusTextarea()
320327
},
321328
resetFile() {
322329
this.message = ''
323330
this.imageFile = null
324331
this.editedMessage.file = null
325332
this.file = null
333+
this.resetTextareaSize()
334+
setTimeout(() => this.focusTextarea(), 0)
326335
},
327336
isImageCheck(file) {
328337
if (!file) return

0 commit comments

Comments
 (0)