From b142638ade1fbca7e5f79dee3b5c9a41973db8fe Mon Sep 17 00:00:00 2001 From: Jake Tigchelaar Date: Mon, 26 Feb 2024 23:30:18 -0500 Subject: [PATCH] fix(useActiveElement/useFocusWithin): replace computedWithControl with locally tracked ref (#3815) --- packages/core/useActiveElement/index.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/useActiveElement/index.ts b/packages/core/useActiveElement/index.ts index 5f9beeb3eff..ddc47bc9b63 100644 --- a/packages/core/useActiveElement/index.ts +++ b/packages/core/useActiveElement/index.ts @@ -1,4 +1,4 @@ -import { computedWithControl } from '@vueuse/shared' +import { ref } from 'vue-demi' import { useEventListener } from '../useEventListener' import type { ConfigurableDocumentOrShadowRoot, ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' @@ -36,19 +36,21 @@ export function useActiveElement( return element } - const activeElement = computedWithControl( - () => null, - () => getDeepActiveElement() as T | null | undefined, - ) + const activeElement = ref() + const trigger = () => { + activeElement.value = getDeepActiveElement() as T | null | undefined + } if (window) { useEventListener(window, 'blur', (event) => { if (event.relatedTarget !== null) return - activeElement.trigger() + trigger() }, true) - useEventListener(window, 'focus', activeElement.trigger, true) + useEventListener(window, 'focus', trigger, true) } + trigger() + return activeElement }