Skip to content

Commit 8d294df

Browse files
committed
fix: use isTouchDevice methods control scrollToTop button display
1 parent aad5b12 commit 8d294df

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

app/components/ScrollToTop.client.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ const isActive = computed(() => !excludedRoutes.has(route.name as string))
99
const SCROLL_TO_TOP_DURATION = 500
1010
1111
const isMounted = useMounted()
12+
const isTouchDeviceClient = shallowRef(false)
1213
const isVisible = shallowRef(false)
1314
const scrollThreshold = 300
1415
const { isSupported: supportsScrollStateQueries } = useCssSupports(
1516
'container-type',
1617
'scroll-state',
1718
{ ssrValue: false },
1819
)
20+
const shouldShowButton = computed(() => isActive.value && isTouchDeviceClient.value)
1921
2022
function onScroll() {
2123
if (supportsScrollStateQueries.value) {
@@ -29,14 +31,15 @@ const { scrollToTop } = useScrollToTop({ duration: SCROLL_TO_TOP_DURATION })
2931
useEventListener('scroll', onScroll, { passive: true })
3032
3133
onMounted(() => {
34+
isTouchDeviceClient.value = isTouchDevice()
3235
onScroll()
3336
})
3437
</script>
3538

3639
<template>
3740
<!-- When CSS scroll-state is supported, use CSS-only visibility -->
3841
<button
39-
v-if="isActive && supportsScrollStateQueries"
42+
v-if="shouldShowButton && supportsScrollStateQueries"
4043
type="button"
4144
class="scroll-to-top-css fixed bottom-4 inset-ie-4 z-50 w-12 h-12 bg-bg-elevated border border-border rounded-full shadow-lg flex items-center justify-center text-fg-muted hover:text-fg transition-colors active:scale-95"
4245
:aria-label="$t('common.scroll_to_top')"
@@ -56,7 +59,7 @@ onMounted(() => {
5659
leave-to-class="opacity-0 translate-y-2"
5760
>
5861
<button
59-
v-if="isActive && isMounted && isVisible"
62+
v-if="shouldShowButton && isMounted && isVisible"
6063
type="button"
6164
class="fixed bottom-4 inset-ie-4 z-50 w-12 h-12 bg-bg-elevated border border-border rounded-full shadow-lg flex items-center justify-center text-fg-muted hover:text-fg transition-colors active:scale-95"
6265
:aria-label="$t('common.scroll_to_top')"

0 commit comments

Comments
 (0)