@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
22 lines (18 loc) • 723 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function scrollIntoView(parent, child) {
if (parent instanceof HTMLElement && child instanceof HTMLElement) {
const parentRect = parent.getBoundingClientRect();
const parentViewableArea = {
height: parent.clientHeight,
width: parent.clientWidth
};
const childRect = child.getBoundingClientRect();
const isViewable = childRect.top >= parentRect.top && childRect.top <= parentRect.top + parentViewableArea.height;
if (!isViewable) {
parent.scrollTop = childRect.top + parent.scrollTop - parentRect.top;
}
}
}
exports.scrollIntoView = scrollIntoView;
//# sourceMappingURL=scroll-into-view.js.map