Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass template refs to slots as functions #19731

Merged
merged 9 commits into from
May 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import { computed, shallowRef, toRef } from 'vue'
import { convertToUnit, genericComponent, propsFactory, useRender } from '@/util'

// Types
import type { Ref } from 'vue'
import type { VDataTableSlotProps } from './VDataTable'
import type { VDataTableHeadersSlots } from './VDataTableHeaders'
import type { VDataTableRowsSlots } from './VDataTableRows'
import type { CellProps, RowProps } from '@/components/VDataTable/types'
import type { GenericProps, SelectItemKey } from '@/util'
import type { FunctionVNodeRef, GenericProps, SelectItemKey } from '@/util'

type VDataTableVirtualSlotProps<T> = Omit<
VDataTableSlotProps<T>,
Expand All @@ -46,7 +45,7 @@ export type VDataTableVirtualSlots<T> = VDataTableRowsSlots<T> & VDataTableHeade
'body.prepend': VDataTableVirtualSlotProps<T>
'body.append': VDataTableVirtualSlotProps<T>
item: {
itemRef: Ref<HTMLElement | undefined>
itemRef: FunctionVNodeRef
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { watch } from 'vue'
import { genericComponent, propsFactory, useRender } from '@/util'

// Types
import type { Ref } from 'vue'
import type { GenericProps } from '@/util'
import type { FunctionVNodeRef, GenericProps } from '@/util'

export const makeVVirtualScrollItemProps = propsFactory({
renderless: Boolean,
Expand All @@ -22,7 +21,7 @@ export const VVirtualScrollItem = genericComponent<new <Renderless extends boole
},
slots: {
default: Renderless extends true ? {
itemRef: Ref<HTMLElement | undefined>
itemRef: FunctionVNodeRef
} : never
}
) => GenericProps<typeof props, typeof slots>>()({
Expand All @@ -45,7 +44,7 @@ export const VVirtualScrollItem = genericComponent<new <Renderless extends boole

useRender(() => props.renderless ? (
<>
{ slots.default?.({ itemRef: resizeRef }) }
{ slots.default?.({ itemRef: el => resizeRef.value = el as HTMLElement }) }
</>
) : (
<div
Expand Down
2 changes: 2 additions & 0 deletions packages/vuetify/src/util/defineComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,5 @@ export type ComponentInstance<T> = T extends { new (): ComponentPublicInstance<a
type ShortEmitsToObject<E> = E extends Record<string, any[]> ? {
[K in keyof E]: (...args: E[K]) => any;
} : E;

export type FunctionVNodeRef = (ref: Element | ComponentPublicInstance | null, refs: Record<string, any>) => void
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading