Skip to content

Commit

Permalink
fix(card): 在不使用loading属性的时候,去掉loading parent
Browse files Browse the repository at this point in the history
  • Loading branch information
huangchen1031 committed Aug 30, 2024
1 parent 56a8d03 commit 3faacb3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,22 @@ const Card = forwardRef<HTMLDivElement, CardProps>((props, ref) => {
</>
);

let childrenNode: React.ReactNode = null;
if (!Reflect.has(props, 'loading')) {
childrenNode = React.cloneElement(card, { style });
} else if (React.isValidElement(loading)) {
childrenNode = React.cloneElement(loading, null, card);
} else {
childrenNode = (
<Loading {...loadingProps} loading={!!loading}>
{card}
</Loading>
);
}

return (
<div ref={ref} className={cardClass} style={style}>
{React.isValidElement(loading) ? (
React.cloneElement(loading, null, card)
) : (
<Loading {...loadingProps} loading={!!loading}>
{card}
</Loading>
)}
{childrenNode}
</div>
);
});
Expand Down

0 comments on commit 3faacb3

Please sign in to comment.