Skip to content

fix: tree虚拟列表加载接口时误将loading高度计算进来 #11844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/amis-core/src/utils/dom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 6 additions & 4 deletions packages/amis-ui/src/components/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand Down
23 changes: 13 additions & 10 deletions packages/amis/src/renderers/Form/InputTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ export default class TreeControl extends React.Component<TreeProps, TreeState> {
// 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});
}
Expand Down Expand Up @@ -305,7 +307,8 @@ export default class TreeControl extends React.Component<TreeProps, TreeState> {
'hideRoot',
'themeCss',
'wrapperCustomStyle',
'heightAuto'
'heightAuto',
'options'
],
prevProps,
props
Expand Down Expand Up @@ -753,12 +756,6 @@ export default class TreeControl extends React.Component<TreeProps, TreeState> {
})}
{...testIdBuilder?.getChild('control').getTestId()}
>
<Spinner
size="sm"
key="info"
show={loading}
loadingConfig={loadingConfig}
/>
{loading ? null : searchable ? (
<>
{this.renderSearch()}
Expand All @@ -767,6 +764,12 @@ export default class TreeControl extends React.Component<TreeProps, TreeState> {
) : (
TreeCmpt
)}
<Spinner
size="sm"
key="info"
show={loading}
loadingConfig={loadingConfig}
/>
</div>
<CustomStyle
{...this.props}
Expand Down
Loading