mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
UI: Hotfix problems with HideIfEmpty
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user