Vize

active-element

Track the focused element of a document.

Package @vizejs/composable/active-element
Own the source vize lib pull composable:active-element
Runtime exports useActiveElement
Gzip budget 1280 B

Usage

import { useActiveElement } from "@vizejs/composable/active-element";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
useActiveElement dom experimental deterministic-fallback stable reactive-scope web, desktop document tryOnScopeDispose

API

useActiveElement

Track the focused element of a document. Listens for capturing focus/blur events on the document, so focus changes anywhere (including inside shadow trees) update the ref. Server renders expose null. Listeners are removed with the owning scope.

function useActiveElement( options: UseActiveElementOptions = {}, ): Readonly<ShallowRef<Element | null>>

Types

ActiveElementHost

Document-like capability observed by useActiveElement.

Member Type Description
activeElement Element | null Currently focused element.

UseActiveElementOptions

Options for useActiveElement.

Member Type Description
deep? boolean Descend into open shadow roots to report the innermost focused element.
host? MaybeRefOrGetter<ActiveElementHost | null | undefined> Reactive document capability for alternate runtimes and tests.