Skip to content

Commit 130a5ac

Browse files
authored
Merge pull request #247 from blocknative/enhancement/fixed-scroll-modal
Make modal fixed and lock scrolling. Closes #246
2 parents 13fba75 + 525ecb4 commit 130a5ac

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/components/Modal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
font-family: 'Helvetica Neue';
1616
justify-content: center;
1717
align-items: center;
18-
position: absolute;
18+
position: fixed;
1919
font-size: 16px;
2020
z-index: 99;
2121
top: 0;

src/views/WalletCheck.svelte

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { get } from 'svelte/store'
3-
3+
import { onDestroy, onMount } from 'svelte'
44
import { fade } from 'svelte/transition'
55
import BigNumber from 'bignumber.js'
66
@@ -54,6 +54,23 @@
5454
renderModule()
5555
}
5656
57+
function lockScroll() {
58+
window.scrollTo(0, 0)
59+
}
60+
61+
let originalOverflowValue
62+
63+
onMount(() => {
64+
originalOverflowValue = window.document.body.style.overflow
65+
window.document.body.style.overflow = 'hidden'
66+
window.addEventListener('scroll', lockScroll)
67+
})
68+
69+
onDestroy(() => {
70+
window.removeEventListener('scroll', lockScroll)
71+
window.document.body.style.overflow = originalOverflowValue
72+
})
73+
5774
async function renderModule() {
5875
checkingModule = true
5976

src/views/WalletSelect.svelte

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import BigNumber from 'bignumber.js'
33
import { get } from 'svelte/store'
44
import { fade } from 'svelte/transition'
5+
import { onDestroy, onMount } from 'svelte'
56
67
import { app, walletInterface, wallet, resetWalletState } from '../stores'
78
@@ -56,6 +57,23 @@
5657
let showingAllWalletModules = false
5758
const showAllWallets = () => (showingAllWalletModules = true)
5859
60+
function lockScroll() {
61+
window.scrollTo(0, 0)
62+
}
63+
64+
let originalOverflowValue
65+
66+
onMount(() => {
67+
originalOverflowValue = window.document.body.style.overflow
68+
window.document.body.style.overflow = 'hidden'
69+
window.addEventListener('scroll', lockScroll)
70+
})
71+
72+
onDestroy(() => {
73+
window.removeEventListener('scroll', lockScroll)
74+
window.document.body.style.overflow = originalOverflowValue
75+
})
76+
5977
renderWalletSelect()
6078
6179
async function renderWalletSelect() {

0 commit comments

Comments
 (0)