Skip to content

Commit

Permalink
fix(NumberField): window is not defined ssr (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia authored Aug 5, 2024
1 parent 6cd1398 commit e7a253d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/radix-vue/src/NumberField/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NumberFormatter, NumberParser } from '@internationalized/number'
import { type MaybeComputedElementRef, unrefElement, useEventListener } from '@vueuse/core'
import { createEventHook, reactiveComputed } from '@vueuse/shared'
import { createEventHook, isClient, reactiveComputed } from '@vueuse/shared'
import { type Ref, computed, ref } from 'vue'

export function usePressedHold(options: { target?: MaybeComputedElementRef, disabled: Ref<boolean> }) {
Expand Down Expand Up @@ -31,7 +31,7 @@ export function usePressedHold(options: { target?: MaybeComputedElementRef, disa

// Handle press event, modified version of useMousePressed
const isPressed = ref(false)
const target = computed(() => unrefElement(options.target) || window)
const target = computed(() => unrefElement(options.target))

const onPressStart = (event: PointerEvent) => {
// Only handle left clicks, and ignore events that bubbled through portals.
Expand All @@ -48,9 +48,8 @@ export function usePressedHold(options: { target?: MaybeComputedElementRef, disa
handlePressEnd()
}

useEventListener(target, 'pointerdown', onPressStart)

if (window) {
if (isClient) {
useEventListener(target || window, 'pointerdown', onPressStart)
useEventListener(window, 'pointerup', onPressRelease)
useEventListener(window, 'pointercancel', onPressRelease)
}
Expand Down

0 comments on commit e7a253d

Please sign in to comment.