@kelvininc/ui-components
Version:
Kelvin UI Components
15 lines (14 loc) • 666 B
JavaScript
import { getCollapsedElement } from "../utils";
export const isElementCollapsed = (element) => {
const collapsedElement = getCollapsedElement(Array.from(element.childNodes));
if (collapsedElement !== undefined) {
const range = new Range();
range.selectNodeContents(collapsedElement);
const { width: rectWidth } = range.getBoundingClientRect();
const { clientWidth: collapsedWidth } = collapsedElement;
// once rectWidth comes as a real value and collapsedWidth as a rounded value, this calculation was incorrect.
if (collapsedWidth >= Math.round(rectWidth))
return false;
}
return true;
};