From 63c8bd436807a838e16cace1131f274beb144e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Thu, 30 Aug 2018 08:05:39 -0700 Subject: [PATCH] fix for missing rows in ManagedTable Summary: When starting with an empty table and adding rows, the scrollOffset of the table might end up with a negative value, which causes rows not to be rendered. See https://github.com/bvaughn/react-window/issues/49 for more details. This only calls `scrollToItem` when the table is actually scrollable to prevent a negative scrollOffset. Reviewed By: passy Differential Revision: D9570518 fbshipit-source-id: 5b08990a353a6d41d0f1bc5c1481d5a5e471bd94 --- src/ui/components/table/ManagedTable.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ui/components/table/ManagedTable.js b/src/ui/components/table/ManagedTable.js index 1942e9476..f45993912 100644 --- a/src/ui/components/table/ManagedTable.js +++ b/src/ui/components/table/ManagedTable.js @@ -272,9 +272,19 @@ class ManagedTable extends React.Component< }; scrollToBottom() { - const {current} = this.tableRef; - if (current && this.props.rows.length > 1) { - current.scrollToItem(this.props.rows.length - 1); + const {current: tableRef} = this.tableRef; + const {current: scrollRef} = this.scrollRef; + if (!tableRef || !scrollRef) { + return; + } + + // only call scrollToItem if the list is actually scrollable (height of the + // content is bigger than it's container). Otherwise this might cause + // problems: https://github.com/bvaughn/react-window/issues/49 + const isScrollable = tableRef.props.height < scrollRef.offsetHeight; + + if (tableRef && this.props.rows.length > 1 && isScrollable) { + tableRef.scrollToItem(this.props.rows.length - 1); } }