From 6bdaa6aff1aaba62768d61495debdd7dc8f75391 Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 18 Jun 2019 09:30:03 -0700 Subject: [PATCH] Keep autoscrolling even when a table is cleared Summary: The logs plugin had an inconsistency where you'd be tailing the logs, and then hit "Clear Logs", which would empty the screen, but as the page fills up again, it would stay in the current position and not scroll with the new ones coming in. This makes it consistent by making the behaviour: ``` If not props.stickyBottom never autoscroll, e.g. for static tables of data else if scrolled to the bottom autoscroll if all the rows fit into the screen at once autoscroll ``` Reviewed By: passy Differential Revision: D15856813 fbshipit-source-id: 1357b0e39b576dbe69d260545b21fdab808d2bd2 --- src/ui/components/table/ManagedTable.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ui/components/table/ManagedTable.js b/src/ui/components/table/ManagedTable.js index 810b071f6..165ed9a4c 100644 --- a/src/ui/components/table/ManagedTable.js +++ b/src/ui/components/table/ManagedTable.js @@ -258,6 +258,18 @@ class ManagedTable extends React.Component< ) { this.scrollToHighlightedRows(); } + if ( + this.props.stickyBottom && + !this.state.shouldScrollToBottom && + this.scrollRef && + this.scrollRef.current && + this.scrollRef.current.parentElement && + this.scrollRef.current.parentElement instanceof HTMLElement && + this.scrollRef.current.offsetHeight <= + this.scrollRef.current.parentElement.offsetHeight + ) { + this.setState({shouldScrollToBottom: true}); + } this.firstUpdate = false; } @@ -569,12 +581,11 @@ class ManagedTable extends React.Component< const parent = current ? current.parentElement : null; if ( this.props.stickyBottom && - scrollDirection === 'forward' && - !this.state.shouldScrollToBottom && current && parent instanceof HTMLElement && - current.offsetHeight - (scrollOffset + parent.offsetHeight) < - parent.offsetHeight + scrollDirection === 'forward' && + !this.state.shouldScrollToBottom && + current.offsetHeight - parent.offsetHeight === scrollOffset ) { this.setState({shouldScrollToBottom: true}); } else if (