UNPKG

focus-svelte

Version:

Focus lock for svelte with zero dependencies.

53 lines (52 loc) 1.85 kB
export interface FocusOptions { /** * enables focus */ enabled?: boolean; /** * determines whether or not to assign `area-hidden="true"` to elements * outside of the trap */ assignAriaHidden?: boolean; /** * focusable indicates whether or not to make the containing element * focusable */ focusable?: boolean; /** * the element to focus upon. * * If the element is not tabbable and `focusable` is set to `true`, the * element with `use:focus` will be granted focus. If `focusable` is falsy, * the first tabbable child node will be granted focus. * * `string` values will be considered query selectors */ element?: HTMLElement | string; /** * focusDelay can either be a number or a function which resolves with a promise * when it is appropriate to set focus on the target Element * * Defaults to `tick` */ focusDelay?: number | (() => Promise<void>); /** * delay can either be a number or an async function which resolves * when it is appropriate to set assign tab indexes and ariaHidden (if applicable) * * Defaults to `tick` */ delay?: number | (() => Promise<void>); /** A Boolean value indicating whether or not the browser should scroll the * document to bring the newly-focused element into view. A value of false * for preventScroll (the default) means that the browser will scroll the * element into view after focusing it. If preventScroll is set to true, no * scrolling will occur. */ preventScroll?: boolean; } export interface FocusAction { update(enabled: boolean): void; update(opts: FocusOptions): void; destroy(): void; } export declare function focus(trap: HTMLElement, opts: FocusOptions | boolean): FocusAction;