fix: 点击收起按钮时,外部容器滚动条不回到顶部

This commit is contained in:
gx-mac 2021-03-07 23:56:49 +08:00
parent 7c2ca7d955
commit a188004ad9
2 changed files with 7 additions and 2 deletions

View File

@ -55,6 +55,7 @@ class Tree extends React.Component {
this.cacheTreeNodes = []; //缓存 treenode 节点数组
this.store = createStore({ rowHeight: 24 }); //rowHeight 树节点的高度,此变量在滚动加载场景很关键
this.latestState = null
this.cachedLatestState = null
}
componentDidMount() {
@ -318,6 +319,7 @@ onExpand(treeNode,keyType) {
const { treeData,lazyLoad } = this.props;
let expanded = !treeNode.props.expanded;
this.latestState = expanded
this.cachedLatestState = expanded
this.latestTreeNode = treeNode.props
const controlled = 'expandedKeys' in this.props;
const expandedKeys = [...this.state.expandedKeys];
@ -1230,12 +1232,15 @@ onExpand(treeNode,keyType) {
}
}
this.selectKeyDomExist = false;
const isFold = !!this.cachedLatestState;
this.cachedLatestState = null;
return (
lazyLoad ?
<InfiniteScroll
className="u-tree-infinite-scroll"
treeList={flatTreeData}
debounceDuration={debounceDuration || 150}
isFold={isFold}
handleTreeListChange={this.handleTreeListChange}
getScrollParent={getScrollContainer}
store={this.store}

View File

@ -222,8 +222,8 @@ export default class InfiniteScroll extends Component {
index += 1;
}
}
if (isNewDataLess) {
parentElement.scrollTop = 0
if (isNewDataLess && !this.props.isFold) {
parentElement.scrollTop = 0 // 如果不是因为点击收起造成的数据减少,则滚动条回到顶部
}
//true 为向下滚动, false 为向上滚动
let isScrollDown = index - currentIndex > 0 ? true : false;