|
156 | 156 | 'textarea-image': imageFile
|
157 | 157 | }"
|
158 | 158 | :style="{
|
159 |
| - height: `${imageDimensions.height - 12}px`, |
160 |
| - 'min-height': `${ |
161 |
| - imageDimensions.height > 20 ? imageDimensions.height - 14 : 20 |
162 |
| - }px`, |
163 |
| - 'padding-left': `${imageDimensions.width + 6}px` |
| 159 | + 'min-height': `${imageDimensions ? imageDimensions.height : 20}px`, |
| 160 | + 'padding-left': `${imageDimensions ? imageDimensions.width : 16}px` |
164 | 161 | }"
|
165 | 162 | v-model="message"
|
166 | 163 | @input="onChangeInput"
|
@@ -262,7 +259,7 @@ export default {
|
262 | 259 | loadingMoreMessages: false,
|
263 | 260 | file: null,
|
264 | 261 | imageFile: null,
|
265 |
| - imageDimensions: { height: '20px', width: '10px' }, |
| 262 | + imageDimensions: null, |
266 | 263 | menuOpened: false,
|
267 | 264 | emojiOpened: false,
|
268 | 265 | emojisList: {},
|
@@ -337,12 +334,14 @@ export default {
|
337 | 334 | },
|
338 | 335 | imageFile() {
|
339 | 336 | setTimeout(() => {
|
340 |
| - if (!this.$refs.imageFile) |
341 |
| - return (this.imageDimensions = { height: 20, width: 10 }) |
342 |
| -
|
343 |
| - this.imageDimensions = { |
344 |
| - height: this.$refs.imageFile.height + 2, |
345 |
| - width: this.$refs.imageFile.width + 20 |
| 337 | + if (!this.$refs.imageFile) { |
| 338 | + this.imageDimensions = null |
| 339 | + setTimeout(() => this.resizeTextarea(), 0) |
| 340 | + } else { |
| 341 | + this.imageDimensions = { |
| 342 | + height: this.$refs.imageFile.height - 10, |
| 343 | + width: this.$refs.imageFile.width + 26 |
| 344 | + } |
346 | 345 | }
|
347 | 346 | }, 20)
|
348 | 347 | }
|
@@ -487,23 +486,20 @@ export default {
|
487 | 486 | if (this.isImageCheck(this.file)) this.imageFile = message.file.url
|
488 | 487 | this.message = message.content
|
489 | 488 |
|
490 |
| - setTimeout(() => this.resizeTextarea(this.$refs['roomTextarea']), 0) |
| 489 | + setTimeout(() => this.resizeTextarea(), 0) |
491 | 490 | },
|
492 | 491 | scrollToBottom() {
|
493 | 492 | const element = this.$refs.scrollContainer
|
494 | 493 | element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' })
|
495 | 494 | },
|
496 |
| - onChangeInput(el) { |
497 |
| - this.autoGrow(el) |
| 495 | + onChangeInput() { |
| 496 | + this.resizeTextarea() |
498 | 497 | this.$emit('typingMessage', this.message)
|
499 | 498 | },
|
500 |
| - autoGrow(el) { |
501 |
| - this.resizeTextarea(el.srcElement) |
502 |
| - }, |
503 |
| - resizeTextarea(textarea) { |
504 |
| - textarea.style.height = 0 |
505 |
| - const offset = this.imageFile ? 2 : 0 |
506 |
| - textarea.style.height = textarea.scrollHeight - 24 + offset + 'px' |
| 499 | + resizeTextarea() { |
| 500 | + const el = this.$refs['roomTextarea'] |
| 501 | + el.style.height = 0 |
| 502 | + el.style.height = el.scrollHeight - 24 + 'px' |
507 | 503 | },
|
508 | 504 | addEmoji(emoji) {
|
509 | 505 | this.message += emoji.icon
|
|
0 commit comments