From f643e7b316639a79cf03da25250ab0fa85f466d5 Mon Sep 17 00:00:00 2001 From: pierre golfier Date: Mon, 5 Feb 2024 16:18:20 +0100 Subject: [PATCH] feat(Textarea): add `maxrows` prop to restrict autoresize (#1302) Co-authored-by: Benjamin Canac --- docs/content/2.components/textarea.md | 12 ++++++++++++ src/runtime/components/forms/Textarea.vue | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/content/2.components/textarea.md b/docs/content/2.components/textarea.md index fa0af370..72724460 100644 --- a/docs/content/2.components/textarea.md +++ b/docs/content/2.components/textarea.md @@ -119,6 +119,18 @@ props: --- :: +Use the `maxrows` prop to set a maximum number of rows when autoresizing. If set to `0`, the Textarea will infinitely grow up. +::component-card +--- +baseProps: + placeholder: 'Search...' + modelValue: 'Here is an autoresize Textarea, write new lines to make the Textarea grow up at a maximum of 5 rows...' +props: + autoresize: true + maxrows: 5 +--- +:: + ### Resize Use the `resize` prop to enable the resize control. diff --git a/src/runtime/components/forms/Textarea.vue b/src/runtime/components/forms/Textarea.vue index 3e51f80f..dfde6238 100644 --- a/src/runtime/components/forms/Textarea.vue +++ b/src/runtime/components/forms/Textarea.vue @@ -66,6 +66,10 @@ export default defineComponent({ type: Number, default: 3 }, + maxrows: { + type: Number, + default: 0 + }, autoresize: { type: Boolean, default: false @@ -160,7 +164,7 @@ export default defineComponent({ const newRows = (scrollHeight - padding) / lineHeight if (newRows > props.rows) { - textarea.value.rows = newRows + textarea.value.rows = props.maxrows ? Math.min(newRows, props.maxrows) : newRows } } }