Skip to content

Commit

Permalink
fix(remove-scroll): resolve an issue where styles are not always rest…
Browse files Browse the repository at this point in the history
…ored correctly
  • Loading branch information
cschroeter committed Oct 28, 2024
1 parent fe17761 commit 85aa147
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-rocks-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/remove-scroll": patch
---

Resolve an issue where styles are not always restored correctly
11 changes: 9 additions & 2 deletions packages/utilities/remove-scroll/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ const LOCK_CLASSNAME = "data-scroll-lock"

function assignStyle(el: HTMLElement | null | undefined, style: Partial<CSSStyleDeclaration>) {
if (!el) return
const previousStyle = el.style.cssText
const previousStyle = Object.keys(style).reduce(
(acc, key) => {
acc[key] = el.style.getPropertyValue(key)
return acc
},
{} as Record<string, string>,
)

Object.assign(el.style, style)
return () => {
el.style.cssText = previousStyle
Object.assign(el.style, previousStyle)
}
}

Expand Down

0 comments on commit 85aa147

Please sign in to comment.