Skip to content

Commit ac35aa7

Browse files
committed
feat(VTextarea): add max-height prop (#22286)
resolves #22284
1 parent 7c53fa0 commit ac35aa7

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

packages/api-generator/src/locale/en/VTextarea.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"prefix": "Displays prefix text.",
88
"rows": "Default row count.",
99
"suffix": "Displays suffix text.",
10+
"maxHeight": "Alternative for **max-rows**. Specifies the maximum height in pixels (including the field padding) for **auto-grow**.",
1011
"maxRows": "Specifies the maximum number of rows for **auto-grow**.",
1112
"autofocus": "The element should be focused as soon as the page loads."
1213
},

packages/docs/src/data/new-in.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@
291291
"prev": "3.11.0"
292292
}
293293
},
294+
"VTextarea": {
295+
"props": {
296+
"maxHeight": "3.11.0"
297+
}
298+
},
294299
"VTextField": {
295300
"props": {
296301
"autocomplete": "3.10.0"
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
<template>
2-
<v-container fluid>
2+
<v-container class="d-flex ga-3 align-start" fluid>
33
<v-textarea
4-
label="Label"
5-
model-value="The Woodman set to work at once, and so sharp was his axe that the tree was soon chopped nearly through."
6-
name="input-7-1"
7-
variant="filled"
4+
v-model="text"
5+
hint="Growing without limit"
86
auto-grow
7+
persistent-hint
8+
></v-textarea>
9+
10+
<v-textarea
11+
v-model="text"
12+
hint="Growing up to 7 rows"
13+
max-rows="7"
14+
auto-grow
15+
persistent-hint
16+
></v-textarea>
17+
18+
<v-textarea
19+
v-model="text"
20+
hint="Growing up to 300px"
21+
max-height="300"
22+
auto-grow
23+
persistent-hint
924
></v-textarea>
1025
</v-container>
1126
</template>
27+
28+
<script setup>
29+
import { ref } from 'vue'
30+
31+
const text = ref('The Woodman set to work at once, and so sharp was his axe that the tree was soon chopped nearly through.')
32+
</script>

packages/vuetify/src/components/VTextarea/VTextarea.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
@include tools.layer('components')
88
.v-textarea
9+
--v-textarea-max-height: initial
10+
911
.v-field
1012
--v-textarea-control-height: var(--v-input-control-height)
1113

1214
.v-field__field
1315
--v-input-control-height: var(--v-textarea-control-height)
1416

1517
.v-field__input
18+
max-height: var(--v-textarea-max-height)
19+
1620
$a: calc((var(--v-field-padding-top, 0) + var(--v-input-padding-top, 0)) - 6px)
1721
$b: calc(var(--v-field-padding-top, 0) + var(--v-input-padding-top, 0) + 4px)
1822
$c: calc(100% - var(--v-textarea-scroll-bar-width, 16px))

packages/vuetify/src/components/VTextarea/VTextarea.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export const makeVTextareaProps = propsFactory({
4444
default: 5,
4545
validator: (v: any) => !isNaN(parseFloat(v)),
4646
},
47+
maxHeight: {
48+
type: [Number, String],
49+
validator: (v: any) => !isNaN(parseFloat(v)),
50+
},
4751
maxRows: {
4852
type: [Number, String],
4953
validator: (v: any) => !isNaN(parseFloat(v)),
@@ -188,7 +192,11 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
188192
parseFloat(props.rows) * lineHeight + padding,
189193
parseFloat(fieldStyle.getPropertyValue('--v-input-control-height'))
190194
)
191-
const maxHeight = parseFloat(props.maxRows!) * lineHeight + padding || Infinity
195+
196+
const maxHeight = props.maxHeight
197+
? parseFloat(props.maxHeight!)
198+
: parseFloat(props.maxRows!) * lineHeight + padding || Infinity
199+
192200
const newHeight = clamp(height ?? 0, minHeight, maxHeight)
193201
rows.value = Math.floor((newHeight - padding) / lineHeight)
194202

@@ -199,6 +207,7 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
199207
onMounted(calculateInputHeight)
200208
watch(model, calculateInputHeight)
201209
watch(() => props.rows, calculateInputHeight)
210+
watch(() => props.maxHeight, calculateInputHeight)
202211
watch(() => props.maxRows, calculateInputHeight)
203212
watch(() => props.density, calculateInputHeight)
204213
watch(rows, val => {
@@ -247,6 +256,7 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
247256
]}
248257
style={[
249258
{
259+
'--v-textarea-max-height': props.maxHeight ? convertToUnit(props.maxHeight) : undefined,
250260
'--v-textarea-scroll-bar-width': convertToUnit(scrollbarWidth.value),
251261
},
252262
props.style,

0 commit comments

Comments
 (0)