Skip to content

Commit

Permalink
feat(Textarea): add maxrows prop to restrict autoresize (#1302)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
  • Loading branch information
pedraal and benjamincanac committed Feb 5, 2024
1 parent 5a5b284 commit f643e7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/content/2.components/textarea.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/components/forms/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export default defineComponent({
type: Number,
default: 3
},
maxrows: {
type: Number,
default: 0
},
autoresize: {
type: Boolean,
default: false
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit f643e7b

Please sign in to comment.