useActiveElement
A hook to track the currently focused element in the document
Loading...
Installation
npx shadcn@latest add @shadcnhooks/use-active-elementAPI
export interface UseActiveElementOptions {
/**
* Search active element deeply inside shadow dom.
* @default true
*/
deep?: boolean
/**
* Track active element when it's removed from the DOM
* Using a MutationObserver under the hood
* @default false
*/
triggerOnRemoval?: boolean
}
export function useActiveElement<T extends Element = HTMLElement>(
options?: UseActiveElementOptions,
): T | nullCredits
Last updated on