Skip to content

Commit

Permalink
fix(ScrollArea): clear setTimeout, eventListener when unmount ScrollA…
Browse files Browse the repository at this point in the history
…reaScrollbarScroll (#672)
  • Loading branch information
teleskop150750 committed Feb 9, 2024
1 parent 8296b78 commit 74872bb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/radix-vue/src/ScrollArea/ScrollAreaScrollbarScroll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ const { state, dispatch } = useStateMachine('hidden', {
},
})
watchEffect(() => {
watchEffect((onCleanup) => {
if (state.value === 'idle') {
window.setTimeout(
const timeId = window.setTimeout(
() => dispatch('HIDE'),
rootContext.scrollHideDelay.value,
)
onCleanup(() => {
window.clearTimeout(timeId)
})
}
})
const debounceScrollEnd = useDebounceFn(() => dispatch('SCROLL_END'), 100)
watchEffect(() => {
watchEffect((onCleanup) => {
const viewport = rootContext.viewport.value
const scrollDirection = scrollbarContext.isHorizontal.value
? 'scrollLeft'
Expand All @@ -69,6 +73,10 @@ watchEffect(() => {
prevScrollPos = scrollPos
}
viewport.addEventListener('scroll', handleScroll)
onCleanup(() => {
viewport.removeEventListener('scroll', handleScroll)
})
}
})
</script>
Expand Down

0 comments on commit 74872bb

Please sign in to comment.