@@ -51,6 +51,7 @@ class BaseTable extends React.PureComponent {
51
51
52
52
const { columns, children, expandedRowKeys, defaultExpandedRowKeys } = props ;
53
53
this . state = {
54
+ scrollbarSize : 0 ,
54
55
hoveredRowKey : null ,
55
56
resizingKey : null ,
56
57
resizingWidth : 0 ,
@@ -96,7 +97,6 @@ class BaseTable extends React.PureComponent {
96
97
this . _horizontalScrollbarSize = 0 ;
97
98
this . _verticalScrollbarSize = 0 ;
98
99
this . _scrollbarPresenceChanged = false ;
99
- this . _scrollbarSizeMeasured = getScrollbarSize ( ) !== undefined ;
100
100
}
101
101
102
102
/**
@@ -629,13 +629,10 @@ class BaseTable extends React.PureComponent {
629
629
}
630
630
631
631
componentDidMount ( ) {
632
- // in SSR getScrollbarSize() === undefined, so we have to measure again here
633
- if ( ! this . _scrollbarSizeMeasured ) {
634
- getScrollbarSize ( ) ;
635
- this . setState ( { } ) ;
632
+ const scrollbarSize = getScrollbarSize ( ) ;
633
+ if ( scrollbarSize > 0 ) {
634
+ this . setState ( { scrollbarSize } ) ;
636
635
}
637
-
638
- this . _maybeScrollbarPresenceChange ( ) ;
639
636
}
640
637
641
638
componentDidUpdate ( prevProps , prevState ) {
@@ -708,28 +705,34 @@ class BaseTable extends React.PureComponent {
708
705
709
706
_calcScrollbarSizes ( ) {
710
707
const { fixed, width } = this . props ;
708
+ const { scrollbarSize } = this . state ;
709
+
711
710
const totalRowsHeight = this . getTotalRowsHeight ( ) ;
712
711
const totalColumnsWidth = this . getTotalColumnsWidth ( ) ;
713
- const scrollbarSize = getScrollbarSize ( ) || 0 ;
714
712
715
713
const prevHorizontalScrollbarSize = this . _horizontalScrollbarSize ;
716
714
const prevVerticalScrollbarSize = this . _verticalScrollbarSize ;
717
715
718
- // we have to set `this._horizontalScrollbarSize` before calling `this._getBodyHeight`
719
- if ( ! fixed || totalColumnsWidth <= width - scrollbarSize ) {
716
+ if ( scrollbarSize === 0 ) {
720
717
this . _horizontalScrollbarSize = 0 ;
721
- this . _verticalScrollbarSize = totalRowsHeight > this . _getBodyHeight ( ) ? scrollbarSize : 0 ;
718
+ this . _verticalScrollbarSize = 0 ;
722
719
} else {
723
- if ( totalColumnsWidth > width ) {
724
- this . _horizontalScrollbarSize = scrollbarSize ;
725
- this . _verticalScrollbarSize =
726
- totalRowsHeight > this . _getBodyHeight ( ) - this . _horizontalScrollbarSize ? scrollbarSize : 0 ;
727
- } else {
720
+ // we have to set `this._horizontalScrollbarSize` before calling `this._getBodyHeight`
721
+ if ( ! fixed || totalColumnsWidth <= width - scrollbarSize ) {
728
722
this . _horizontalScrollbarSize = 0 ;
729
- this . _verticalScrollbarSize = 0 ;
730
- if ( totalRowsHeight > this . _getBodyHeight ( ) ) {
723
+ this . _verticalScrollbarSize = totalRowsHeight > this . _getBodyHeight ( ) ? scrollbarSize : 0 ;
724
+ } else {
725
+ if ( totalColumnsWidth > width ) {
731
726
this . _horizontalScrollbarSize = scrollbarSize ;
732
- this . _verticalScrollbarSize = scrollbarSize ;
727
+ this . _verticalScrollbarSize =
728
+ totalRowsHeight > this . _getBodyHeight ( ) - this . _horizontalScrollbarSize ? scrollbarSize : 0 ;
729
+ } else {
730
+ this . _horizontalScrollbarSize = 0 ;
731
+ this . _verticalScrollbarSize = 0 ;
732
+ if ( totalRowsHeight > this . _getBodyHeight ( ) ) {
733
+ this . _horizontalScrollbarSize = scrollbarSize ;
734
+ this . _verticalScrollbarSize = scrollbarSize ;
735
+ }
733
736
}
734
737
}
735
738
}
@@ -748,7 +751,7 @@ class BaseTable extends React.PureComponent {
748
751
this . _scrollbarPresenceChanged = false ;
749
752
750
753
onScrollbarPresenceChange ( {
751
- size : getScrollbarSize ( ) ,
754
+ size : this . state . scrollbarSize ,
752
755
horizontal : this . _horizontalScrollbarSize > 0 ,
753
756
vertical : this . _verticalScrollbarSize > 0 ,
754
757
} ) ;
0 commit comments