From 71e110036ea0339207c168f268907dcc0de277e8 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 17 Mar 2022 14:02:07 +0800 Subject: [PATCH] feat: popover support empty slot --- components/popover/index.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/popover/index.tsx b/components/popover/index.tsx index 7025ea7e7..3e189de9b 100644 --- a/components/popover/index.tsx +++ b/components/popover/index.tsx @@ -3,7 +3,7 @@ import { computed, defineComponent, ref } from 'vue'; import Tooltip from '../tooltip'; import abstractTooltipProps from '../tooltip/abstractTooltipProps'; import PropTypes from '../_util/vue-types'; -import { initDefaultProps } from '../_util/props-util'; +import { filterEmpty, initDefaultProps } from '../_util/props-util'; import { withInstall } from '../_util/type'; import useConfigInject from '../_util/hooks/useConfigInject'; import omit from '../_util/omit'; @@ -39,10 +39,14 @@ const Popover = defineComponent({ const { prefixCls, configProvider } = useConfigInject('popover', props); const rootPrefixCls = computed(() => configProvider.getPrefixCls()); const getOverlay = () => { - const { title = slots.title?.(), content = slots.content?.() } = props; + const { title = filterEmpty(slots.title?.()), content = filterEmpty(slots.content?.()) } = + props; + const hasTitle = !!(Array.isArray(title) ? title.length : title); + const hasContent = !!(Array.isArray(content) ? content.length : title); + if (!hasTitle && !hasContent) return undefined; return ( <> - {title &&
{title}
} + {hasTitle &&
{title}
}
{content}
);