Skip to content

Commit 96caaa0

Browse files
committed
fix: card empty slot render
1 parent 7789cb2 commit 96caaa0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

components/_util/props-util/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,15 @@ export function filterEmpty(children = []) {
370370
return res.filter(c => !isEmptyElement(c));
371371
}
372372

373+
export function filterEmptyWithUndefined(children) {
374+
if (children) {
375+
const coms = filterEmpty(children);
376+
return coms.length ? coms : undefined;
377+
} else {
378+
return children;
379+
}
380+
}
381+
373382
export function mergeProps() {
374383
const args = [].slice.call(arguments, 0);
375384
const props = {};

components/card/Card.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Tabs from '../tabs';
44
import Row from '../row';
55
import Col from '../col';
66
import PropTypes from '../_util/vue-types';
7-
import { flattenChildren, isEmptyElement } from '../_util/props-util';
7+
import { flattenChildren, isEmptyElement, filterEmptyWithUndefined } from '../_util/props-util';
88
import type { SizeType } from '../config-provider';
99
import isPlainObject from 'lodash-es/isPlainObject';
1010
import useConfigInject from '../_util/hooks/useConfigInject';
@@ -88,11 +88,11 @@ const Card = defineComponent({
8888
hoverable,
8989
activeTabKey,
9090
defaultActiveTabKey,
91-
tabBarExtraContent = slots.tabBarExtraContent?.(),
92-
title = slots.title?.(),
93-
extra = slots.extra?.(),
94-
actions = slots.actions?.(),
95-
cover = slots.cover?.(),
91+
tabBarExtraContent = filterEmptyWithUndefined(slots.tabBarExtraContent?.()),
92+
title = filterEmptyWithUndefined(slots.title?.()),
93+
extra = filterEmptyWithUndefined(slots.extra?.()),
94+
actions = filterEmptyWithUndefined(slots.actions?.()),
95+
cover = filterEmptyWithUndefined(slots.cover?.()),
9696
} = props;
9797
const children = flattenChildren(slots.default?.());
9898
const pre = prefixCls.value;

0 commit comments

Comments
 (0)