Skip to content

Commit

Permalink
fix(useFocus): focused should be false when element is undefined (
Browse files Browse the repository at this point in the history
#1580)

* fix(useFocus): `focused` should be `false` when `element` is undefined

* chore: update
  • Loading branch information
webfansplz committed May 16, 2022
1 parent 9b28628 commit f0067ac
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/useFocus/index.ts
@@ -1,5 +1,6 @@
import type { Ref } from 'vue-demi'
import { computed, watch } from 'vue-demi'
import { isDef } from '@vueuse/shared'
import type { MaybeElementRef } from '../unrefElement'
import { unrefElement } from '../unrefElement'
import { useActiveElement } from '../useActiveElement'
Expand Down Expand Up @@ -36,7 +37,7 @@ export function useFocus(target: MaybeElementRef, options: UseFocusOptions = {})
const targetElement = computed(() => unrefElement(target))
const focused = computed({
get() {
return activeElement.value === targetElement.value
return isDef(activeElement.value) && isDef(targetElement.value) && activeElement.value === targetElement.value
},
set(value: boolean) {
if (!value && focused.value)
Expand Down

0 comments on commit f0067ac

Please sign in to comment.