Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit a2907c8

Browse files
author
Brian Vaughn
committed
Snapshot selector auto-scrolls to ensure selected commit is visible
1 parent ad38466 commit a2907c8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

plugins/Profiler/views/SnapshotSelector.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ type SnapshotSelectorState = {|
103103
|};
104104

105105
class SnapshotSelector extends PureComponent<SnapshotSelectorProps, SnapshotSelectorState> {
106+
// $FlowFixMe createRef()
107+
listRef = React.createRef();
108+
109+
componentDidUpdate(prevProps) {
110+
// Make sure any newly selected snapshot is visible within the list.
111+
if (this.props.snapshotIndex !== prevProps.snapshotIndex) {
112+
this.listRef.current.scrollToItem(this.props.snapshotIndex);
113+
}
114+
}
115+
106116
state: SnapshotSelectorState = {
107117
isMouseDown: false,
108118
};
@@ -186,6 +196,7 @@ class SnapshotSelector extends PureComponent<SnapshotSelectorProps, SnapshotSele
186196
itemCount={snapshots.length}
187197
itemData={itemData}
188198
itemSize={listData.itemSize}
199+
ref={this.listRef}
189200
width={width}
190201
>
191202
{ListItem}

0 commit comments

Comments
 (0)