Skip to content

Commit b142638

Browse files
authored
fix(useActiveElement/useFocusWithin): replace computedWithControl with locally tracked ref (#3815)
1 parent 74e86b5 commit b142638

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/core/useActiveElement/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computedWithControl } from '@vueuse/shared'
1+
import { ref } from 'vue-demi'
22
import { useEventListener } from '../useEventListener'
33
import type { ConfigurableDocumentOrShadowRoot, ConfigurableWindow } from '../_configurable'
44
import { defaultWindow } from '../_configurable'
@@ -36,19 +36,21 @@ export function useActiveElement<T extends HTMLElement>(
3636
return element
3737
}
3838

39-
const activeElement = computedWithControl(
40-
() => null,
41-
() => getDeepActiveElement() as T | null | undefined,
42-
)
39+
const activeElement = ref<T | null | undefined>()
40+
const trigger = () => {
41+
activeElement.value = getDeepActiveElement() as T | null | undefined
42+
}
4343

4444
if (window) {
4545
useEventListener(window, 'blur', (event) => {
4646
if (event.relatedTarget !== null)
4747
return
48-
activeElement.trigger()
48+
trigger()
4949
}, true)
50-
useEventListener(window, 'focus', activeElement.trigger, true)
50+
useEventListener(window, 'focus', trigger, true)
5151
}
5252

53+
trigger()
54+
5355
return activeElement
5456
}

0 commit comments

Comments
 (0)