From 8e76eb9faa17f9e6c670b8796ba79413acbcb006 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Fri, 14 Dec 2018 13:06:49 -0800 Subject: [PATCH] Ensure horizontal scrollbar is not shown --- src/SkinTable.js | 14 ++++++++++---- src/utils.js | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/SkinTable.js b/src/SkinTable.js index cae717a1..3ae8f16f 100644 --- a/src/SkinTable.js +++ b/src/SkinTable.js @@ -36,8 +36,13 @@ class SkinTable extends React.Component { } _handleResize() { - // TODO: Try to recompute the scroll position - this.setState(Utils.getWindowSize()); + const { windowWidth, windowHeight } = Utils.getWindowSize(); + if ( + windowWidth != this.state.windowWidth || + windowHeight != this.state.windowHeight + ) { + this.setState({ windowWidth, windowHeight }); + } const { rowHeight, columnWidth } = this._getTableDimensions(); this.props.setCellSize({ rowHeight, columnWidth }); } @@ -45,8 +50,9 @@ class SkinTable extends React.Component { componentDidMount() { window.addEventListener("scroll", this._handleScroll); window.addEventListener("resize", this._handleResize); - const { rowHeight, columnWidth } = this._getTableDimensions(); - this.props.setCellSize({ rowHeight, columnWidth }); + // Our initial render may have caused the scrollbar to appear. So we + // remeasure. + this._handleResize(); } componentWillUnmount() { diff --git a/src/utils.js b/src/utils.js index 8900b4fd..4accbcf4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,8 +21,8 @@ export function getWindowSize() { d = document, e = d.documentElement, g = d.getElementsByTagName("body")[0], - x = w.innerWidth || e.clientWidth || g.clientWidth, - y = w.innerHeight || e.clientHeight || g.clientHeight; + x = e.clientWidth || g.clientWidth || w.innerWidth, + y = e.clientHeight || g.clientHeight || w.innerHeight; return { windowWidth: x,