Select the inputs below to see the changes
Current Active Element: null

useActiveElement

Reactive document.activeElement

Usage

import { useActiveElement } from '@vueuse/core'

const activeElement = useActiveElement()

watch(activeElement, (el) => {
  console.log('focus changed to', el)
})

Component

<UseActiveElement v-slot="{ element }">
  Active element is {{ element.dataset.id }}
</UseActiveElement>
Learn more about component usage

Type Declarations

/**
 * Reactive `document.activeElement`
 *
 * @see /useActiveElement
 * @param options
 */
export declare function useActiveElement<T extends HTMLElement>(
  options?: ConfigurableWindow
): ComputedRef<T | null | undefined>

Source

SourceDemoDocs