fn
useFocusWithin
v0.0.14testeddemoReactive tracking of whether an element or any of its
descendants are focused, backed by the focusin/focusout events.
Example
ts
const el = useTemplateRef<HTMLElement>('el');
const { focused } = useFocusWithin(el);Demo
Loading demo…
Signature
ts
export function useFocusWithin(
target: MaybeComputedElementRef,
options: UseFocusWithinOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | MaybeComputedElementRef | Element to track |
options? | UseFocusWithinOptions | Options |
Returns
UseFocusWithinReturn{ focused } reactive focus-within state| Property | Type | Description |
|---|---|---|
focused | ComputedRef<boolean> | Whether the element or any of its descendants currently hold focus. |