UI: Hotfix problems with HideIfEmpty

This commit is contained in:
Fuma Nama
2025-05-17 14:30:45 +08:00
parent 06a18a0be4
commit e955a98da3
2 changed files with 21 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-ui': patch
---
Hotfix problems with `HideIfEmpty`
@@ -17,7 +17,22 @@ const init = `function isEmpty(node) {
return true;
}`;
const isEmpty: (node: HTMLElement) => boolean = eval(`${init}; isEmpty`);
function isEmpty(node: HTMLElement) {
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes.item(i);
if (child.nodeType === Node.TEXT_NODE) {
return false;
} else if (
child.nodeType === Node.ELEMENT_NODE &&
window.getComputedStyle(child as HTMLElement).display !== 'none'
) {
return false;
}
}
return true;
}
/**
* The built-in CSS `:empty` selector cannot detect if the children is hidden, classes such as `md:hidden` causes it to fail.