forked from p96170835/amis
去掉动态根据数据更新宽度,避免不断扩宽问题
This commit is contained in:
parent
903f043c07
commit
93eb715d0b
|
@ -179,6 +179,8 @@ export default class VirtualList extends React.PureComponent<Props, State> {
|
||||||
// 自适应宽度
|
// 自适应宽度
|
||||||
updateRootWidth() {
|
updateRootWidth() {
|
||||||
const itemsDom = this.rootNode.children[0].children;
|
const itemsDom = this.rootNode.children[0].children;
|
||||||
|
const scrollbarWidth =
|
||||||
|
window.innerWidth - document.documentElement.clientWidth || 15;
|
||||||
const containerWidth = this.rootNode.parentElement!.getBoundingClientRect()
|
const containerWidth = this.rootNode.parentElement!.getBoundingClientRect()
|
||||||
.width;
|
.width;
|
||||||
let maxItemWidth = 0;
|
let maxItemWidth = 0;
|
||||||
|
@ -188,10 +190,8 @@ export default class VirtualList extends React.PureComponent<Props, State> {
|
||||||
maxItemWidth = itemWidth;
|
maxItemWidth = itemWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (containerWidth >= maxItemWidth) {
|
if (maxItemWidth > containerWidth) {
|
||||||
this.rootNode.style.width = containerWidth + 'px';
|
this.rootNode.style.width = maxItemWidth + scrollbarWidth + 'px';
|
||||||
} else {
|
|
||||||
this.rootNode.style.width = maxItemWidth + 'px';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,6 @@ export default class VirtualList extends React.PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(_: Props, prevState: State) {
|
componentDidUpdate(_: Props, prevState: State) {
|
||||||
this.updateRootWidth();
|
|
||||||
const {offset, scrollChangeReason} = this.state;
|
const {offset, scrollChangeReason} = this.state;
|
||||||
if (
|
if (
|
||||||
prevState.offset !== offset &&
|
prevState.offset !== offset &&
|
||||||
|
|
Loading…
Reference in New Issue