Skip to content

Commit dc27986

Browse files
authored
[core-v2.2.7, react-v2.1.6] : fix - Add methods to prevent scrolling of background when modal is open (#976)
* Add methods to prevent scrolling of background when modal is open * Update react package version * Update core version in demo
1 parent cba2a65 commit dc27986

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.2.6",
3+
"version": "2.2.7",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",

packages/core/src/views/shared/Modal.svelte

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,32 @@
1515

1616
<script lang="ts">
1717
import { fade } from 'svelte/transition'
18+
import { onDestroy, onMount } from 'svelte'
1819
20+
const body = document.body
21+
onMount(() => {
22+
window.addEventListener(
23+
'scroll',
24+
() => {
25+
document.documentElement.style.setProperty(
26+
'--scroll-y',
27+
`${window.scrollY}px`
28+
)
29+
},
30+
{ passive: true }
31+
)
32+
const scrollY =
33+
document.documentElement.style.getPropertyValue('--scroll-y')
34+
body.style.position = 'fixed'
35+
body.style.top = `-${scrollY}`
36+
})
37+
38+
onDestroy(() => {
39+
const scrollY = body.style.top
40+
body.style.position = ''
41+
body.style.top = ''
42+
window.scrollTo(0, parseInt(scrollY || '0') * -1)
43+
})
1944
export let close: () => void
2045
</script>
2146

@@ -48,7 +73,7 @@
4873
.modal-overflow {
4974
overflow: hidden;
5075
}
51-
76+
5277
.modal-styling {
5378
border-radius: var(--onboard-modal-border-radius, var(--border-radius-1));
5479
box-shadow: var(--onboard-modal-box-shadow, var(--box-shadow-0));

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"webpack-dev-server": "4.7.4"
2323
},
2424
"dependencies": {
25-
"@web3-onboard/core": "^2.2.3",
25+
"@web3-onboard/core": "^2.2.7",
2626
"@web3-onboard/fortmatic": "^2.0.2",
2727
"@web3-onboard/gnosis": "^2.0.1",
2828
"@web3-onboard/injected-wallets": "^2.0.5",

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "Collection of React Hooks for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@web3-onboard/common": "^2.0.7",
25-
"@web3-onboard/core": "^2.2.5"
25+
"@web3-onboard/core": "^2.2.7"
2626
},
2727
"peerDependencies": {
2828
"react": "^17.0.2"

0 commit comments

Comments
 (0)