@@ -6,6 +6,7 @@ import { findFooterByUuid, findHeaderByUuid } from "./util";
6
6
interface AutoSizerProps {
7
7
numRows : number ;
8
8
rowHeight ?: number ;
9
+ headerHeight ?: number ;
9
10
tableWidth ?: number ;
10
11
tableHeight ?: number ;
11
12
minTableHeight ?: number ;
@@ -60,13 +61,22 @@ const findCorrectHeight = ({
60
61
return containerHeight || computedHeight ;
61
62
} ;
62
63
63
- const calculateHeight = ( rowHeight : number , uuid : string , size : number , hasFooter : boolean ) => {
64
+ const calculateHeight = (
65
+ rowHeight : number ,
66
+ headerHeight : number ,
67
+ uuid : string ,
68
+ size : number ,
69
+ hasFooter : boolean
70
+ ) => {
64
71
// get the header, footer and nodes
65
72
const header = findHeaderByUuid ( uuid ) ;
66
73
const nodes = [ ...( header ?. nextElementSibling ?. children || [ ] ) ] as HTMLElement [ ] ;
67
74
let footerHeight = findFooterByUuid ( uuid ) ?. offsetHeight || 0 ;
68
75
69
76
if ( ! ! header && ! ! nodes . length ) {
77
+ // header height to use
78
+ const headerOffset = headerHeight > 0 ? headerHeight : header . offsetHeight ;
79
+
70
80
// get border height
71
81
let borders = 0 ;
72
82
const table = header . parentElement ?. parentElement ;
@@ -76,12 +86,12 @@ const calculateHeight = (rowHeight: number, uuid: string, size: number, hasFoote
76
86
77
87
// perform calculation
78
88
if ( rowHeight > 0 ) {
79
- return header . offsetHeight + nodes . length * rowHeight + footerHeight + borders ;
89
+ return headerOffset + nodes . length * rowHeight + footerHeight + borders ;
80
90
}
81
91
82
92
let overscan = 0 ;
83
93
return (
84
- header . offsetHeight +
94
+ headerOffset +
85
95
nodes . reduce ( ( pv , c ) => {
86
96
overscan = c . offsetHeight ;
87
97
return pv + c . offsetHeight ;
@@ -92,14 +102,15 @@ const calculateHeight = (rowHeight: number, uuid: string, size: number, hasFoote
92
102
) ;
93
103
}
94
104
95
- // try and guess the footer height
105
+ // try and guess the header and footer height
106
+ const headerOffset = headerHeight || DEFAULT_HEADER_HEIGHT ;
96
107
if ( ! footerHeight && hasFooter ) {
97
- footerHeight = DEFAULT_HEADER_HEIGHT ;
108
+ footerHeight = headerOffset ;
98
109
}
99
110
100
111
// if the header and nodes are not specified, guess the height
101
112
const height = Math . max ( rowHeight || DEFAULT_ROW_HEIGHT , 10 ) ;
102
- return height * Math . min ( size || 10 , 10 ) + DEFAULT_HEADER_HEIGHT + footerHeight ;
113
+ return height * Math . min ( size || 10 , 10 ) + headerOffset + footerHeight ;
103
114
} ;
104
115
105
116
/**
@@ -115,6 +126,7 @@ const AutoSizer = ({
115
126
tableHeight,
116
127
minTableHeight,
117
128
maxTableHeight,
129
+ headerHeight,
118
130
children
119
131
} : AutoSizerProps ) => {
120
132
// hooks
@@ -137,8 +149,8 @@ const AutoSizer = ({
137
149
return tableHeight ;
138
150
}
139
151
140
- return calculateHeight ( rowHeight || 0 , uuid , numRows , hasFooter ) ;
141
- } , [ tableHeight , rowHeight , numRows , uuid , hasFooter ] ) ;
152
+ return calculateHeight ( rowHeight || 0 , headerHeight || 0 , uuid , numRows , hasFooter ) ;
153
+ } , [ tableHeight , rowHeight , headerHeight , numRows , uuid , hasFooter ] ) ;
142
154
143
155
// calculate the actual height of the table
144
156
const height = findCorrectHeight ( {
0 commit comments