Skip to content

Commit

Permalink
fix(scrollbar): should restore scroll state on deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Jun 5, 2022
1 parent 5a90208 commit 0bc47e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"treemate": "^0.3.11",
"vdirs": "^0.1.8",
"vooks": "^0.2.12",
"vueuc": "^0.4.37"
"vueuc": "^0.4.38"
},
"sideEffects": false,
"homepage": "https://www.naiveui.com",
Expand Down
28 changes: 26 additions & 2 deletions src/_internal/scrollbar/src/Scrollbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
CSSProperties,
watchEffect,
VNode,
HTMLAttributes
HTMLAttributes,
onActivated,
onDeactivated
} from 'vue'
import { on, off } from 'evtd'
import { VResizeObserver } from 'vueuc'
Expand Down Expand Up @@ -269,9 +271,31 @@ const Scrollbar = defineComponent({
return contentRef.value
})

let isDeactivated = false
let activateStateInitialized = false
onActivated(() => {
isDeactivated = false
if (!activateStateInitialized) {
activateStateInitialized = true
return
}
// remount
scrollTo({ top: scrollX, left: scrollY })
})
onDeactivated(() => {
isDeactivated = true
if (!activateStateInitialized) {
activateStateInitialized = true
}
})

// methods
const handleContentResize = sync
const handleContentResize = (): void => {
if (isDeactivated) return
sync()
}
const handleContainerResize = (e: ResizeObserverEntry): void => {
if (isDeactivated) return
const { onResize } = props
if (onResize) onResize(e)
sync()
Expand Down

0 comments on commit 0bc47e1

Please sign in to comment.