@appnest/focus-trap
Version:
A lightweight web component to trap focus within a DOM node
70 lines (69 loc) • 1.9 kB
TypeScript
export interface IFocusTrap {
inactive: boolean;
readonly focused: boolean;
focusFirstElement: (() => void);
focusLastElement: (() => void);
getFocusableChildren: (() => HTMLElement[]);
}
export declare class FocusTrap extends HTMLElement implements IFocusTrap {
static readonly observedAttributes: string[];
inactive: boolean;
private $backup;
private debounceId;
private $start;
private $end;
private _focused;
/**
* Returns whether the element currently has focus.
*/
readonly focused: boolean;
constructor();
/**
* Hooks up the component.
*/
connectedCallback(): void;
/**
* Tears down the component.
*/
disconnectedCallback(): void;
/**
* When the attributes changes we need to re-render the template.
*/
attributeChangedCallback(): void;
/**
* Focuses the first focusable element in the focus trap.
*/
focusFirstElement(): void;
/**
* Focuses the last focusable element in the focus trap.
*/
focusLastElement(): void;
/**
* Returns a list of the focusable children found within the element.
*/
getFocusableChildren(): HTMLElement[];
/**
* Focuses on either the last or first focusable element.
* @param {boolean} trapToEnd
*/
protected trapFocus(trapToEnd?: boolean): void;
/**
* When the element gains focus this function is called.
*/
private onFocusIn;
/**
* When the element looses its focus this function is called.
*/
private onFocusOut;
/**
* Updates the has focus property and updates the view.
* The update is debounces because the focusin and focusout out
* might fire multiple times in a row.
* @param value
*/
private updateHasFocus;
/**
* Updates the template.
*/
protected render(): void;
}