Skip to content

Commit e72d4d3

Browse files
feat(VTextarea): add update:rows event (#21226)
closes #21133
1 parent 6790e1e commit e72d4d3

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
},
1313
"events": {
1414
"keydown": "Emitted when **any** key is pressed, textarea must be focused.",
15-
"mousedown:control": "Event that is emitted when using mousedown on the main control area."
15+
"mousedown:control": "Event that is emitted when using mousedown on the main control area.",
16+
"update:rows": "Emitted when the number of rows changes."
1617
},
1718
"slots": {
1819
"counter": "Slot for the input’s counter text."

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
7171
'mousedown:control': (e: MouseEvent) => true,
7272
'update:focused': (focused: boolean) => true,
7373
'update:modelValue': (val: string) => true,
74+
'update:rows': (rows: number) => true,
7475
},
7576

7677
setup (props, { attrs, emit, slots }) {
@@ -180,6 +181,9 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
180181
watch(() => props.rows, calculateInputHeight)
181182
watch(() => props.maxRows, calculateInputHeight)
182183
watch(() => props.density, calculateInputHeight)
184+
watch(rows, val => {
185+
emit('update:rows', val)
186+
})
183187

184188
let observer: ResizeObserver | undefined
185189
watch(sizerRef, val => {

packages/vuetify/src/components/VTextarea/__tests__/VTextarea.spec.browser.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,20 @@ describe('VTextarea', () => {
5454
await userEvent.keyboard('Lorem ipsum dolor sit amet consectetur adipisicing elit. ')
5555
await expect.poll(() => el.offsetHeight).toBe(80)
5656
})
57+
58+
it('should emit update rows', async () => {
59+
await page.viewport(500, 500)
60+
const model = ref('Lorem ipsum dolor sit amet, consectetur adipiscing elit')
61+
const rows = ref(1)
62+
render(() => (
63+
<Application>
64+
<div>
65+
<VTextarea auto-grow rows="1" v-model={ model.value } onUpdate:rows={ val => { rows.value = val } } />
66+
</div>
67+
</Application>
68+
))
69+
await userEvent.tab()
70+
await userEvent.keyboard('Lorem ipsum dolor')
71+
expect(rows.value).toBe(2)
72+
})
5773
})

0 commit comments

Comments
 (0)