Skip to content

Commit

Permalink
fix(VDataTable): apply fixed-header when sticky prop is set
Browse files Browse the repository at this point in the history
fixes #20903
  • Loading branch information
KaelWD authored and johnleider committed Jan 23, 2025
1 parent 6181018 commit 2795792
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/api-generator/src/locale/en/VDataTableHeaders.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"disableSort": "Toggles rendering of sort button.",
"sortAscIcon": "Icon used for ascending sort button.",
"sortDescIcon": "Icon used for descending sort button.",
"sticky": "Sticks the header to the top of the table."
"sticky": "Deprecated, use `fixed-header` instead.",
"fixedHeader": "Sticks the header to the top of the table."
},
"slots": {
"[`column.${string}`]": "Slot for custom rendering of a column.",
Expand Down
1 change: 1 addition & 0 deletions packages/vuetify/src/components/VDataTable/VDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export const VDataTable = genericComponent<new <T extends readonly any[], V>(
]}
style={ props.style }
{ ...tableProps }
fixedHeader={ props.fixedHeader || props.sticky }
>
{{
top: () => slots.top?.(slotProps.value),
Expand Down
11 changes: 7 additions & 4 deletions packages/vuetify/src/components/VDataTable/VDataTableHeaders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export type VDataTableHeadersSlots = {

export const makeVDataTableHeadersProps = propsFactory({
color: String,
sticky: Boolean,
disableSort: Boolean,
fixedHeader: Boolean,
multiSort: Boolean,
sortAscIcon: {
type: IconValue,
Expand All @@ -74,6 +74,9 @@ export const makeVDataTableHeadersProps = propsFactory({
type: Object as PropType<Record<string, any>>,
},

/** @deprecated */
sticky: Boolean,

...makeDisplayProps(),
...makeLoaderProps(),
}, 'VDataTableHeaders')
Expand All @@ -91,12 +94,12 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
const { loaderClasses } = useLoader(props)

function getFixedStyles (column: InternalDataTableHeader, y: number): CSSProperties | undefined {
if (!props.sticky && !column.fixed) return undefined
if (!(props.sticky || props.fixedHeader) && !column.fixed) return undefined

return {
position: 'sticky',
left: column.fixed ? convertToUnit(column.fixedOffset) : undefined,
top: props.sticky ? `calc(var(--v-table-header-height) * ${y})` : undefined,
top: (props.sticky || props.fixedHeader) ? `calc(var(--v-table-header-height) * ${y})` : undefined,
}
}

Expand Down Expand Up @@ -127,7 +130,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
const headerCellClasses = computed(() => ([
'v-data-table__th',
{
'v-data-table__th--sticky': props.sticky,
'v-data-table__th--sticky': (props.sticky || props.fixedHeader),
},
displayClasses.value,
loaderClasses.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const VDataTableServer = genericComponent<new <T extends readonly any[],
]}
style={ props.style }
{ ...tableProps }
fixedHeader={ props.fixedHeader || props.sticky }
>
{{
top: () => slots.top?.(slotProps.value),
Expand All @@ -170,7 +171,6 @@ export const VDataTableServer = genericComponent<new <T extends readonly any[],
<thead key="thead" class="v-data-table__thead" role="rowgroup">
<VDataTableHeaders
{ ...dataTableHeadersProps }
sticky={ props.fixedHeader }
v-slots={ slots }
/>
</thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
]}
style={ props.style }
{ ...tableProps }
fixedHeader={ props.fixedHeader || props.sticky }
>
{{
top: () => slots.top?.(slotProps.value),
Expand All @@ -208,7 +209,6 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
<thead key="thead">
<VDataTableHeaders
{ ...dataTableHeadersProps }
sticky={ props.fixedHeader }
v-slots={ slots }
/>
</thead>
Expand Down

0 comments on commit 2795792

Please sign in to comment.