export declare type FocusableTarget = HTMLElement | {
focus(): void;
};
declare type FocusTrapConfig = {
/** The element inside which we want to trap focus */
container: HTMLElement;
/**
* An element to focus on inside the focus trap after it is activated.
* (default: first focusable element inside the focus trap)
* (fallback: first focusable element inside the focus trap, then the container itself)
*/
elementToFocusWhenActivated?: FocusableTarget | null;
/**
* An element to focus on outside the focus trap after it is deactivated.
* (default: last focused element before the focus trap was activated)
* (fallback: none)
*/
elementToFocusWhenDeactivated?: FocusableTarget | null;
/** Whether pressing the escape key should deactivate the focus trap */
shouldDeactivateOnEscape?: boolean;
/** Escape key handler */
onEscape?: (event: KeyboardEvent) => void;
/** Whether clicking outside the focus trap container should deactivate the focus trap */
shouldDeactivateOnOutsideClick?: boolean | ((event: MouseEvent | TouchEvent) => boolean);
/** Click outside handler */
onOutsideClick?: (event: MouseEvent | TouchEvent, shouldPreventFocusControl: boolean) => void;
/** Whether pointer events happening outside the focus trap container should be blocked */
shouldBlockOutsideClick?: boolean;
/** Whether scrolling should be locked */
shouldLockScroll?: boolean;
};
export declare type FocusTrap = {
/** Gets whether the focus trap is currently active */
isActive: () => boolean;
/** Activates the focus trap */
activate: () => void;
/** Pauses the focus trap (not listening for events anymore) */
pause: () => void;
/** Resumes the focus trap */
resume: () => void;
/** Deactivates the focus trap */
deactivate: (options?: DeactivateOptions) => void;
/** Updates the config (partial) */
updateConfig: (config: Partial) => void;
};
declare type DeactivateOptions = {
/**
* Whether we should prevent the focus from being controlled on deactivation
* (returned to `elementFocusedBeforeActivation` or `elementToFocusWhenDeactivated`).
* It is useful to turn this on in some situations.
* For example, when the focus trap is deactivated via click outside
* and the element clicked is tabbable (it is fine for the focus to remain on that element in this case)
* (default: false)
*/
shouldPreventFocusControl?: boolean;
};
/**
* Creates a new focus trap which can be programmatically activated/deactivated
*/
export declare function createFocusTrap(initialConfig: FocusTrapConfig): FocusTrap;
export {};