Skip to content

Commit

Permalink
fix(Loading/QDrawer/QDialog): prevent scroll - do not scroll back if …
Browse files Browse the repository at this point in the history
…route has changed since it was activated #15211
  • Loading branch information
rstoenescu committed Jan 11, 2023
1 parent 6b363e1 commit 93e7bb5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ui/dev/src/pages/layout/layout.vue
Expand Up @@ -202,6 +202,12 @@
</q-card>
</q-expansion-item>

<q-item to="/">
<q-item-section>
<q-item-label>Homepage</q-item-label>
</q-item-section>
</q-item>

<q-item-label header>
Folders
</q-item-label>
Expand Down
10 changes: 9 additions & 1 deletion ui/src/utils/prevent-scroll.js
Expand Up @@ -10,6 +10,7 @@ let
vpPendingUpdate = false,
bodyLeft,
bodyTop,
href,
closeTimer = null

function onWheel (e) {
Expand Down Expand Up @@ -96,6 +97,8 @@ function apply (action) {
bodyLeft = body.style.left
bodyTop = body.style.top

href = window.location.href

body.style.left = `-${ scrollPositionX }px`
body.style.top = `-${ scrollPositionY }px`

Expand All @@ -108,6 +111,7 @@ function apply (action) {

body.classList.add('q-body--prevent-scroll')
document.qScrollPrevented = true

if (client.is.ios === true) {
if (hasViewport === true) {
window.scrollTo(0, 0)
Expand Down Expand Up @@ -146,7 +150,11 @@ function apply (action) {
body.style.left = bodyLeft
body.style.top = bodyTop

window.scrollTo(scrollPositionX, scrollPositionY)
// scroll back only if route has not changed
if (window.location.href === href) {
window.scrollTo(scrollPositionX, scrollPositionY)
}

maxScrollTop = void 0
}
}
Expand Down

0 comments on commit 93e7bb5

Please sign in to comment.