diff --git a/app/components/ScrollToTop.client.vue b/app/components/ScrollToTop.client.vue index e1e70ec5f..7e25ba6c3 100644 --- a/app/components/ScrollToTop.client.vue +++ b/app/components/ScrollToTop.client.vue @@ -6,7 +6,10 @@ const excludedRoutes = new Set(['index', 'code']) const isActive = computed(() => !excludedRoutes.has(route.name as string)) +const SCROLL_TO_TOP_DURATION = 500 + const isMounted = useMounted() +const isTouchDeviceClient = shallowRef(false) const isVisible = shallowRef(false) const scrollThreshold = 300 const { isSupported: supportsScrollStateQueries } = useCssSupports( @@ -14,21 +17,21 @@ const { isSupported: supportsScrollStateQueries } = useCssSupports( 'scroll-state', { ssrValue: false }, ) +const shouldShowButton = computed(() => isActive.value && isTouchDeviceClient.value) function onScroll() { - if (!supportsScrollStateQueries.value) { + if (supportsScrollStateQueries.value) { return } isVisible.value = window.scrollY > scrollThreshold } -function scrollToTop() { - window.scrollTo({ top: 0, behavior: 'smooth' }) -} +const { scrollToTop } = useScrollToTop({ duration: SCROLL_TO_TOP_DURATION }) useEventListener('scroll', onScroll, { passive: true }) onMounted(() => { + isTouchDeviceClient.value = isTouchDevice() onScroll() }) @@ -36,11 +39,11 @@ onMounted(() => {