@@ -207,23 +207,37 @@ export class Table2 extends AbstractComponent2<TableProps, TableState, TableSnap
207
207
208
208
private refHandlers = {
209
209
cellContainer : ( ref : HTMLElement | null ) => ( this . cellContainerElement = ref ) ,
210
- columnHeader : ( ref : HTMLElement | null ) => ( this . columnHeaderElement = ref ) ,
210
+ columnHeader : ( ref : HTMLElement | null ) => {
211
+ this . columnHeaderElement = ref ;
212
+ if ( ref != null ) {
213
+ this . columnHeaderHeight = ref . clientHeight ;
214
+ }
215
+ } ,
211
216
quadrantStack : ( ref : TableQuadrantStack ) => ( this . quadrantStackInstance = ref ) ,
212
217
rootTable : ( ref : HTMLElement | null ) => ( this . rootTableElement = ref ) ,
213
- rowHeader : ( ref : HTMLElement | null ) => ( this . rowHeaderElement = ref ) ,
218
+ rowHeader : ( ref : HTMLElement | null ) => {
219
+ this . rowHeaderElement = ref ;
220
+ if ( ref != null ) {
221
+ this . rowHeaderWidth = ref . clientWidth ;
222
+ }
223
+ } ,
214
224
scrollContainer : ( ref : HTMLElement | null ) => ( this . scrollContainerElement = ref ) ,
215
225
} ;
216
226
217
227
private cellContainerElement ?: HTMLElement | null ;
218
228
219
229
private columnHeaderElement ?: HTMLElement | null ;
220
230
231
+ private columnHeaderHeight = Grid . MIN_COLUMN_HEADER_HEIGHT ;
232
+
221
233
private quadrantStackInstance ?: TableQuadrantStack ;
222
234
223
235
private rootTableElement ?: HTMLElement | null ;
224
236
225
237
private rowHeaderElement ?: HTMLElement | null ;
226
238
239
+ private rowHeaderWidth = Grid . MIN_ROW_HEADER_WIDTH ;
240
+
227
241
private scrollContainerElement ?: HTMLElement | null ;
228
242
229
243
/*
@@ -761,23 +775,32 @@ export class Table2 extends AbstractComponent2<TableProps, TableState, TableSnap
761
775
selectedRegionTransform,
762
776
} = this . props ;
763
777
764
- if ( this . grid === null || this . locator === undefined || viewportRect === undefined ) {
765
- return undefined ;
766
- }
767
-
768
778
const classes = classNames ( Classes . TABLE_COLUMN_HEADERS , {
769
779
[ Classes . TABLE_SELECTION_ENABLED ] : isSelectionModeEnabled (
770
780
this . props as TablePropsWithDefaults ,
771
781
RegionCardinality . FULL_COLUMNS ,
772
782
) ,
773
783
} ) ;
774
784
775
- const columnIndices = this . grid . getColumnIndicesInRect ( viewportRect , enableGhostCells ) ;
785
+ if ( this . grid === null || this . locator === undefined || viewportRect === undefined ) {
786
+ // if we haven't mounted yet (which we need in order for grid/viewport calculations),
787
+ // we still want to hand a DOM ref over to TableQuadrantStack for later
788
+ return < div className = { classes } ref = { refHandler } /> ;
789
+ }
790
+
791
+ // if we have horizontal overflow, no need to render ghost columns
792
+ // (this avoids problems like https://github.com/palantir/blueprint/issues/5027)
793
+ const hasHorizontalOverflow = this . locator . hasHorizontalOverflow ( this . rowHeaderWidth , viewportRect ) ;
794
+ const columnIndices = this . grid . getColumnIndicesInRect (
795
+ viewportRect ,
796
+ hasHorizontalOverflow ? false : enableGhostCells ,
797
+ ) ;
798
+
776
799
const columnIndexStart = showFrozenColumnsOnly ? 0 : columnIndices . columnIndexStart ;
777
800
const columnIndexEnd = showFrozenColumnsOnly ? this . getMaxFrozenColumnIndex ( ) : columnIndices . columnIndexEnd ;
778
801
779
802
return (
780
- < div className = { classes } >
803
+ < div className = { classes } ref = { refHandler } >
781
804
< ColumnHeader
782
805
defaultColumnWidth = { defaultColumnWidth ! }
783
806
enableMultipleSelection = { enableMultipleSelection }
@@ -789,7 +812,6 @@ export class Table2 extends AbstractComponent2<TableProps, TableState, TableSnap
789
812
loading = { hasLoadingOption ( loadingOptions , TableLoadingOption . COLUMN_HEADERS ) }
790
813
locator = { this . locator }
791
814
maxColumnWidth = { maxColumnWidth ! }
792
- measurableElementRef = { refHandler }
793
815
minColumnWidth = { minColumnWidth ! }
794
816
onColumnWidthChanged = { this . handleColumnWidthChanged }
795
817
onFocusedCell = { this . handleFocus }
@@ -831,18 +853,24 @@ export class Table2 extends AbstractComponent2<TableProps, TableState, TableSnap
831
853
selectedRegionTransform,
832
854
} = this . props ;
833
855
834
- if ( this . grid === null || this . locator === undefined || viewportRect === undefined ) {
835
- return undefined ;
836
- }
837
-
838
856
const classes = classNames ( Classes . TABLE_ROW_HEADERS , {
839
857
[ Classes . TABLE_SELECTION_ENABLED ] : isSelectionModeEnabled (
840
858
this . props as TablePropsWithDefaults ,
841
859
RegionCardinality . FULL_ROWS ,
842
860
) ,
843
861
} ) ;
844
862
845
- const rowIndices = this . grid . getRowIndicesInRect ( viewportRect , enableGhostCells ) ;
863
+ if ( this . grid === null || this . locator === undefined || viewportRect === undefined ) {
864
+ // if we haven't mounted yet (which we need in order for grid/viewport calculations),
865
+ // we still want to hand a DOM ref over to TableQuadrantStack for later
866
+ return < div className = { classes } ref = { refHandler } /> ;
867
+ }
868
+
869
+ // if we have vertical overflow, no need to render ghost rows
870
+ // (this avoids problems like https://github.com/palantir/blueprint/issues/5027)
871
+ const hasVerticalOverflow = this . locator . hasVerticalOverflow ( this . columnHeaderHeight , viewportRect ) ;
872
+ const rowIndices = this . grid . getRowIndicesInRect ( viewportRect , hasVerticalOverflow ? false : enableGhostCells ) ;
873
+
846
874
const rowIndexStart = showFrozenRowsOnly ? 0 : rowIndices . rowIndexStart ;
847
875
const rowIndexEnd = showFrozenRowsOnly ? this . getMaxFrozenRowIndex ( ) : rowIndices . rowIndexEnd ;
848
876
@@ -926,8 +954,15 @@ export class Table2 extends AbstractComponent2<TableProps, TableState, TableSnap
926
954
return undefined ;
927
955
}
928
956
929
- const rowIndices = this . grid . getRowIndicesInRect ( viewportRect , enableGhostCells ) ;
930
- const columnIndices = this . grid . getColumnIndicesInRect ( viewportRect , enableGhostCells ) ;
957
+ // if we have vertical/horizontal overflow, no need to render ghost rows/columns (respectively)
958
+ // (this avoids problems like https://github.com/palantir/blueprint/issues/5027)
959
+ const hasVerticalOverflow = this . locator . hasVerticalOverflow ( this . columnHeaderHeight , viewportRect ) ;
960
+ const hasHorizontalOverflow = this . locator . hasHorizontalOverflow ( this . rowHeaderWidth , viewportRect ) ;
961
+ const rowIndices = this . grid . getRowIndicesInRect ( viewportRect , hasVerticalOverflow ? false : enableGhostCells ) ;
962
+ const columnIndices = this . grid . getColumnIndicesInRect (
963
+ viewportRect ,
964
+ hasHorizontalOverflow ? false : enableGhostCells ,
965
+ ) ;
931
966
932
967
// start beyond the frozen area if rendering unrelated quadrants, so we
933
968
// don't render duplicate cells underneath the frozen ones.
@@ -1232,13 +1267,12 @@ export class Table2 extends AbstractComponent2<TableProps, TableState, TableSnap
1232
1267
} ;
1233
1268
1234
1269
private handleBodyScroll = ( event : React . SyntheticEvent < HTMLElement > ) => {
1235
- // Prevent the event from propagating to avoid a resize event on the
1236
- // resize sensor.
1270
+ // Prevent the event from propagating to avoid a resize event on the resize sensor.
1237
1271
event . stopPropagation ( ) ;
1238
1272
1239
1273
if ( this . locator != null && ! this . state . isLayoutLocked ) {
1240
- const viewportRect = this . locator . getViewportRect ( ) ;
1241
- this . updateViewportRect ( viewportRect ) ;
1274
+ const newViewportRect = this . locator . getViewportRect ( ) ;
1275
+ this . updateViewportRect ( newViewportRect ) ;
1242
1276
}
1243
1277
} ;
1244
1278
0 commit comments