fix(frontend): Fix autosize within hidden components

This commit is contained in:
Faton Ramadani
2024-04-17 16:46:44 +02:00
parent 68c8649a13
commit fdc59b1ec7
+7 -21
View File
@@ -14,30 +14,16 @@ export const action = (node) => {
node.dispatchEvent(update)
}
const getParents = (element: Node): HTMLElement[] => {
const parents: HTMLElement[] = []
while (element.parentNode && element.parentNode.nodeName.toLowerCase() !== 'body') {
element = element.parentNode as HTMLElement
parents.push(element as HTMLElement)
}
return parents
}
const hasInvisibleParent = (): boolean => {
return getParents(node).some(
(parent) => parent.classList.contains('hidden') || parent.style.display === 'none'
)
}
const setInitialHeight = () => {
if (!hasInvisibleParent()) {
adjustHeight()
}
}
const adjustHeight = () => {
let height = 0
const style = window.getComputedStyle(node)
const visible = style.getPropertyValue('visibility') === 'hidden'
if (visible === false) {
return
}
if (node.value) {
height = node.scrollHeight
} else {