Skip to content
Open
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
25 changes: 24 additions & 1 deletion packages/components/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ const parentKey = Symbol() as InjectionKey<{
assertMouseLeave: (ev: MouseEvent) => void;
}>;

/** 判断是否为空字符串,或是空插槽 */
function isEmptyContent(node: any) {
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter type 'any' is too broad and reduces type safety. Consider using a more specific type like 'VNode | string | null | undefined' or creating a union type for the expected node types.

Copilot uses AI. Check for mistakes.
if (['', undefined, null].includes(node)) return true;

const innerNodes = node instanceof Array ? node : [node];
const r = innerNodes.filter((node) => {
// 过滤注释节点
if (node?.type?.toString() === 'Symbol(Comment)') return false;

// 检查 VNode 是否为空
if (node && typeof node === 'object' && node.type) {
// 如果 children 为空字符串或空数组,认为是空节点
if (node.children === '' || (Array.isArray(node.children) && node.children.length === 0)) {
return false;
}
}

return true;
});

return !r.length;
}

function getPopperPlacement(placement: TdPopupProps['placement']): Placement {
return placement.replace(/-(left|top)$/, '-start').replace(/-(right|bottom)$/, '-end') as Placement;
}
Expand Down Expand Up @@ -498,7 +521,7 @@ export default defineComponent({

return () => {
const content = renderTNodeJSX('content');
const hidePopup = props.hideEmptyPopup && ['', undefined, null].includes(content);
const hidePopup = props.hideEmptyPopup && isEmptyContent(content);

const overlay =
visible.value || !props.destroyOnClose ? (
Expand Down
9 changes: 3 additions & 6 deletions packages/components/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export default defineComponent({
const formItem = inject(FormItemInjectionKey, undefined);
const emitBlur = (e: FocusEvent) => {
if (!e.target) return;
adjustTextareaHeight();
focused.value = false;
props.onBlur?.(innerValue.value, { e });
formItem?.handleBlur();
Expand Down Expand Up @@ -188,7 +187,9 @@ export default defineComponent({
// watch
watch(
() => innerValue.value,
() => adjustTextareaHeight(),
() => {
nextTick(() => adjustTextareaHeight());
},
);

watch(refTextareaElem, (el) => {
Expand All @@ -208,10 +209,6 @@ export default defineComponent({
}
});

watch(innerValue, () => {
nextTick(() => adjustTextareaHeight());
});

watch(() => props.autosize, adjustTextareaHeight, { deep: true });

expose({
Expand Down
3 changes: 0 additions & 3 deletions packages/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ export default defineComponent({
});
return () => {
const content = renderTNodeJSX('content');
if (!content && !props.content) {
return renderContent('default', 'triggerElement');
}
return (
<Popup
{...omit(popupProps.value, ['content', 'default'])}
Expand Down
Loading