From ba643d9faa3761c336e18bfb4671db6e21e88397 Mon Sep 17 00:00:00 2001 From: Sylvain Marroufin Date: Mon, 4 Apr 2022 14:19:23 +0200 Subject: [PATCH] fix(Textarea): autoresize (#43) --- src/runtime/components/forms/Textarea.vue | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runtime/components/forms/Textarea.vue b/src/runtime/components/forms/Textarea.vue index c9ad92aa..4cbd04b8 100644 --- a/src/runtime/components/forms/Textarea.vue +++ b/src/runtime/components/forms/Textarea.vue @@ -104,15 +104,19 @@ export default { const autoResize = () => { if (props.autoresize) { + textarea.value.rows = props.rows + const styles = window.getComputedStyle(textarea.value) const paddingTop = parseInt(styles.paddingTop) const paddingBottom = parseInt(styles.paddingBottom) const padding = paddingTop + paddingBottom - const initialHeight = (parseInt(styles.height) - padding) / textarea.value.rows - const scrollHeight = textarea.value.scrollHeight - padding - const newRows = Math.ceil(scrollHeight / initialHeight) + const lineHeight = parseInt(styles.lineHeight) + const { scrollHeight } = textarea.value + const newRows = (scrollHeight - padding) / lineHeight - textarea.value.rows = newRows + if (newRows > props.rows) { + textarea.value.rows = newRows + } } }