Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/api-generator/src/locale/en/VTextarea.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"events": {
"keydown": "Emitted when **any** key is pressed, textarea must be focused.",
"mousedown:control": "Event that is emitted when using mousedown on the main control area."
"mousedown:control": "Event that is emitted when using mousedown on the main control area.",
"update:rows": "Emitted when the number of rows changes."
},
"slots": {
"counter": "Slot for the input’s counter text."
Expand Down
4 changes: 4 additions & 0 deletions packages/vuetify/src/components/VTextarea/VTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
'mousedown:control': (e: MouseEvent) => true,
'update:focused': (focused: boolean) => true,
'update:modelValue': (val: string) => true,
'update:rows': (rows: number) => true,
},

setup (props, { attrs, emit, slots }) {
Expand Down Expand Up @@ -187,6 +188,9 @@ export const VTextarea = genericComponent<VTextareaSlots>()({
watch(() => props.rows, calculateInputHeight)
watch(() => props.maxRows, calculateInputHeight)
watch(() => props.density, calculateInputHeight)
watch(rows, val => {
emit('update:rows', val)
})

let observer: ResizeObserver | undefined
watch(sizerRef, val => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,20 @@ describe('VTextarea', () => {
await userEvent.keyboard('Lorem ipsum dolor sit amet consectetur adipisicing elit. ')
await expect.poll(() => el.offsetHeight).toBe(80)
})

it('should emit update rows', async () => {
await page.viewport(500, 500)
const model = ref('Lorem ipsum dolor sit amet, consectetur adipiscing elit')
const rows = ref(1)
render(() => (
<Application>
<div>
<VTextarea auto-grow rows="1" v-model={ model.value } onUpdate:rows={ val => { rows.value = val } } />
</div>
</Application>
))
await userEvent.tab()
await userEvent.keyboard('Lorem ipsum dolor')
expect(rows.value).toBe(2)
})
})
7 changes: 6 additions & 1 deletion packages/vuetify/src/composables/virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {

function calculateOffset (index: number) {
index = clamp(index, 0, items.value.length - 1)
return offsets[index] || 0
const whole = Math.floor(index)
const fraction = index % 1
const next = whole + 1
const wholeOffset = offsets[whole] || 0
const nextOffset = offsets[next] || wholeOffset
return wholeOffset + (nextOffset - wholeOffset) * fraction
}

function calculateIndex (scrollTop: number) {
Expand Down