Bootstrap

API focustrack

activeElement$

function

activeElement$(): null | Element

A readable store that tracks the currently active (focused) element in the document.

This store is only active in a browser environment. When not in a browser environment, it will be a readable store with a null value.

Returns

null | Element

Example
import { activeElement$ } from './focustrack';

activeElement$.subscribe((element) => {
  console.log('Active element:', element);
});

The store updates whenever the active element changes, such as when the user focuses on a different input field or clicks on a different part of the document.


createHasFocus

function

createHasFocus(): HasFocus

Create a HasFocus

Returns

HasFocus

a HasFocus


HasFocus

interface

Interface representing an element that can have focus tracking.

Properties
directive

directive: Directive

Directive to put on some elements.


hasFocus$

hasFocus$: ReadableSignal<boolean>

Store that contains true if the activeElement is one of the elements which has the directive, or any of their descendants.