From 6705af85bdb0a240c5beae3ca6dfd251f2e7c393 Mon Sep 17 00:00:00 2001 From: Segun Adebayo Date: Sun, 24 Apr 2022 09:52:50 +0400 Subject: [PATCH] chore: update --- packages/utilities/dom/src/body-scroll-lock.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/utilities/dom/src/body-scroll-lock.ts b/packages/utilities/dom/src/body-scroll-lock.ts index 8d06143e6d..3e443362b7 100644 --- a/packages/utilities/dom/src/body-scroll-lock.ts +++ b/packages/utilities/dom/src/body-scroll-lock.ts @@ -22,19 +22,19 @@ export function preventBodyScroll(opts?: PreventScrollOptions) { const docEl = doc.documentElement function preventScrollStandard() { - if (docEl.getAttribute("data-prevent-scroll") === "true") return + if (docEl.hasAttribute("scroll-lock")) return const fn = pipe( setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), - () => docEl.setAttribute("data-prevent-scroll", "true"), + () => docEl.setAttribute("scroll-lock", "true"), ) - return () => fn?.() + return pipe(fn, () => docEl.removeAttribute("scroll-lock")) } function preventScrollMobileSafari() { - if (docEl.getAttribute("data-prevent-scroll") === "true") return + if (docEl.hasAttribute("scroll-lock")) return let scrollable: HTMLElement | undefined let lastY = 0 @@ -121,13 +121,14 @@ export function preventBodyScroll(opts?: PreventScrollOptions) { addDomEvent(doc, "touchend", onTouchEnd, { passive: false, capture: true }), addDomEvent(doc, "focus", onFocus, true), addDomEvent(win, "scroll", onWindowScroll), - () => docEl.setAttribute("data-prevent-scroll", "true"), + () => docEl.setAttribute("scroll-lock", "true"), ) return () => { restoreStyles() removeEvents() win.scrollTo(scrollX, scrollY) + docEl.removeAttribute("scroll-lock") } }