Skip to content

Commit 79bcb27

Browse files
committed
fix(VOtpInput): only autofocus if autofocus prop is set
1 parent e447ee5 commit 79bcb27

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

packages/vuetify/src/components/VOtpInput/VOtpInput.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { makeFocusProps, useFocus } from '@/composables/focus'
1313
import { useIntersectionObserver } from '@/composables/intersectionObserver'
1414
import { useLocale } from '@/composables/locale'
1515
import { useProxiedModel } from '@/composables/proxiedModel'
16+
import { useToggleScope } from '@/composables/toggleScope'
1617

1718
// Utilities
1819
import { computed, effectScope, nextTick, ref, toRef, watch, watchEffect } from 'vue'
@@ -98,16 +99,18 @@ export const VOtpInput = genericComponent<VOtpInputSlots>()({
9899
const inputRef = ref<HTMLInputElement[]>([])
99100
const current = computed(() => inputRef.value[focusIndex.value])
100101

101-
const intersectScope = effectScope()
102-
intersectScope.run(() => {
103-
const { intersectionRef, isIntersecting } = useIntersectionObserver()
104-
watch(isIntersecting, v => {
105-
if (!v) return
106-
intersectionRef.value?.focus()
107-
intersectScope.stop()
108-
})
109-
watchEffect(() => {
110-
intersectionRef.value = inputRef.value[0]
102+
useToggleScope(() => props.autofocus, () => {
103+
const intersectScope = effectScope()
104+
intersectScope.run(() => {
105+
const { intersectionRef, isIntersecting } = useIntersectionObserver()
106+
watchEffect(() => {
107+
intersectionRef.value = inputRef.value[0]
108+
})
109+
watch(isIntersecting, v => {
110+
if (!v) return
111+
intersectionRef.value?.focus()
112+
intersectScope.stop()
113+
})
111114
})
112115
})
113116

0 commit comments

Comments
 (0)