import { CocoComponent } from "@js/coco"; import { withSizeObserver } from "@js/base/mixins"; export default CocoComponent("appSeamlessTextarea", () => { return { use: [withSizeObserver()], height: null, observer: null, value: null, options: ["multiline", "focus"], init() { this.value = this.$refs.textarea.value; this.$nextTick(() => { this.onResize(); if (this.$options.focus) { this.$refs.textarea.focus(); this.$refs.textarea.selectionStart = this.$refs.textarea.value.length; } }); }, onResize() { const textarea = this.$refs.textarea; if (textarea) { const styles = window.getComputedStyle(textarea); const fontSize = styles.getPropertyValue("font-size"); textarea.style.height = "4px"; let newHeight = textarea.scrollHeight - parseInt(fontSize, 10) * 0.16; textarea.style.height = `${newHeight}px`; if (this.height !== newHeight) { this.height = newHeight; } } }, }; });