From a390b2aa3652bdf488a1eb37348d98558617dcfd Mon Sep 17 00:00:00 2001 From: Daniel Roos <96danielroos@gmail.com> Date: Thu, 5 Sep 2019 09:49:28 +0200 Subject: [PATCH] Split Table._setScrollbarWidth by adding public function Table.getScrollbarWidth (#1411) * Create public method Table.getScrollbarWidth * Add documentation for Table.getScrollbarWidth --- docs/Table.md | 4 ++++ source/Table/Table.js | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/Table.md b/docs/Table.md index 7df6440e9..3309b24d9 100644 --- a/docs/Table.md +++ b/docs/Table.md @@ -61,6 +61,10 @@ This may be appropriate if the underlying row data has changed but the row sizes Gets offset for a given row and alignment. +##### getScrollbarWidth + +Gets the scrollbar width used to pad the table-header. + ##### measureAllRows Pre-measure all rows in a `Table`. diff --git a/source/Table/Table.js b/source/Table/Table.js index c8f816324..088944f52 100644 --- a/source/Table/Table.js +++ b/source/Table/Table.js @@ -337,6 +337,17 @@ export default class Table extends React.PureComponent { } } + getScrollbarWidth() { + if (this.Grid) { + const Grid = findDOMNode(this.Grid); + const clientWidth = Grid.clientWidth || 0; + const offsetWidth = Grid.offsetWidth || 0; + return offsetWidth - clientWidth; + } + + return 0; + } + componentDidMount() { this._setScrollbarWidth(); } @@ -726,13 +737,8 @@ export default class Table extends React.PureComponent { } _setScrollbarWidth() { - if (this.Grid) { - const Grid = findDOMNode(this.Grid); - const clientWidth = Grid.clientWidth || 0; - const offsetWidth = Grid.offsetWidth || 0; - const scrollbarWidth = offsetWidth - clientWidth; + const scrollbarWidth = this.getScrollbarWidth(); - this.setState({scrollbarWidth}); - } + this.setState({scrollbarWidth}); } }