diff --git a/packages/amis-core/src/utils/dom.tsx b/packages/amis-core/src/utils/dom.tsx index c9c4ae25f6f..b40e0ab0943 100644 --- a/packages/amis-core/src/utils/dom.tsx +++ b/packages/amis-core/src/utils/dom.tsx @@ -382,7 +382,12 @@ export function calculateHeight( let nextSibling = selfNode.nextElementSibling as HTMLElement; while (nextSibling) { const positon = getComputedStyle(nextSibling).position; - if (positon !== 'absolute' && positon !== 'fixed') { + const className = nextSibling.className; + if ( + positon !== 'absolute' && + positon !== 'fixed' && + !className.includes('Spinner') // 过滤掉Loading + ) { const rect1 = selfNode.getBoundingClientRect(); const rect2 = nextSibling.getBoundingClientRect(); diff --git a/packages/amis-ui/src/components/Tree.tsx b/packages/amis-ui/src/components/Tree.tsx index 8b18b3834db..4bed34a9391 100644 --- a/packages/amis-ui/src/components/Tree.tsx +++ b/packages/amis-ui/src/components/Tree.tsx @@ -1612,11 +1612,13 @@ export class TreeSelector extends React.Component< // 虚拟列表 对应元素 const virtualElement = this.virtualListRef.current!; - const virtualHeight = - treeElement!.offsetHeight - - calculateHeight(treeElement!, virtualElement!); + if (treeElement && virtualElement) { + const virtualHeight = + treeElement!.offsetHeight - + calculateHeight(treeElement, virtualElement); - this.setState({virtualHeight: virtualHeight}); + this.setState({virtualHeight: virtualHeight}); + } } else { this.setState({virtualHeight: flattenedOptions.length * itemHeight}); } diff --git a/packages/amis/src/renderers/Form/InputTree.tsx b/packages/amis/src/renderers/Form/InputTree.tsx index d40ad7f476f..743f12276f4 100644 --- a/packages/amis/src/renderers/Form/InputTree.tsx +++ b/packages/amis/src/renderers/Form/InputTree.tsx @@ -271,10 +271,12 @@ export default class TreeControl extends React.Component { // tree 对应元素 const treeElement = this.treeRef.root.current; - const treeHeight = - formElement!.offsetHeight - calculateHeight(formElement!, treeElement!); + if (formElement && treeElement) { + const treeHeight = + formElement!.offsetHeight - calculateHeight(formElement, treeElement); - this.setState({treeHeight: treeHeight}); + this.setState({treeHeight: treeHeight}); + } } else { this.setState({treeHeight: 0}); } @@ -305,7 +307,8 @@ export default class TreeControl extends React.Component { 'hideRoot', 'themeCss', 'wrapperCustomStyle', - 'heightAuto' + 'heightAuto', + 'options' ], prevProps, props @@ -753,12 +756,6 @@ export default class TreeControl extends React.Component { })} {...testIdBuilder?.getChild('control').getTestId()} > - {loading ? null : searchable ? ( <> {this.renderSearch()} @@ -767,6 +764,12 @@ export default class TreeControl extends React.Component { ) : ( TreeCmpt )} +