Files
developer-roadmap/src/lib/dom.ts
T
Neil d7ff5b9abc Ensure when TopicDetail is open document.body stops scrolling (#6285)
* fix: ensure TopicDetail locks the body when open

* chore: ensure 'overflow-hidden' is always available via safelist

* revert: prettier changes
2024-07-30 22:05:20 +01:00

20 lines
502 B
TypeScript

export function replaceChildren(parentNode: Element, newChild: Element) {
if (parentNode.replaceChildren) {
return parentNode.replaceChildren(newChild);
}
parentNode.innerHTML = '';
parentNode.append(newChild);
}
export function lockBodyScroll(shouldLock: boolean) {
const isClient = document && 'body' in document;
if (!isClient) return;
if (shouldLock) {
document.body.classList.add('overflow-hidden');
} else {
document.body.classList.remove('overflow-hidden');
}
}