R
fn

useActiveElement

v0.0.15testeddemo

Reactive `document.activeElement`, traversing open shadow roots.

Examples

ts
const active = useActiveElement();
ts
// keep tracking even if the focused node is detached from the DOM
const active = useActiveElement({ triggerOnRemoval: true });

Demo

Loading demo…

Signature

ts
export function useActiveElement<T extends HTMLElement>(
  options: UseActiveElementOptions ={ ... }

Type Parameters

Textends HTMLElement

Parameters

ParameterTypeDescription
options?UseActiveElementOptionsOptions

Returns

UseActiveElementReturn<T>The currently focused element