- Name
release- Kind
- method
- Type
() => void- Requirement
- required
- Description
- Idempotent. Removes the container's keydown listener and the document's focusin reclaim listener, and restores focus per the `returnFocus` rule.
DocsAPI referenceHeadlessfocus-trap
focus-trap headless API
The core connector and vanilla mount are always visible. Use the framework choice to inspect native composition, props, outputs, context and hooks for the selected adapter.
@grassroot/ui-headless-core/focus-trap
Core connector and vanilla API
FocusTrapHandle
interfaceinterface FocusTrapHandle { /** Idempotent. Removes the container's keydown listener and the * document's focusin reclaim listener, and restores focus per the * `returnFocus` rule. */ release(): void;}release() => voidFocusTrapOptions
interfaceinterface FocusTrapOptions { /** Element to focus on trap; default first tabbable, else the container * itself (given tabindex="-1" if it has none). */ readonly initialFocus?: () => HTMLElement | null; /** Element to restore on release; default the element focused at trap * time. Restored only if the candidate still has a callable `focus` * function (not merely `isConnected`). Returning `null` explicitly opts * OUT of restoration entirely; only an absent option (or a `undefined` * return) falls back to the previously-focused element. */ readonly returnFocus?: () => HTMLElement | null;}initialFocus() => HTMLElement | nullreturnFocus() => HTMLElement | null- Name
initialFocus- Kind
- property
- Type
() => HTMLElement | null- Requirement
- optional
- Description
- Element to focus on trap; default first tabbable, else the container itself (given tabindex="-1" if it has none).
- Name
returnFocus- Kind
- property
- Type
() => HTMLElement | null- Requirement
- optional
- Description
- Element to restore on release; default the element focused at trap time. Restored only if the candidate still has a callable `focus` function (not merely `isConnected`). Returning `null` explicitly opts OUT of restoration entirely; only an absent option (or a `undefined` return) falls back to the previously-focused element.
isFocusEscaped
functiondeclare function isFocusEscaped(container: MinimalContainerLike, active: unknown): boolean;containerMinimalContainerLikeactiveunknownreturnboolean- Name
container- Kind
- parameter
- Type
MinimalContainerLike- Requirement
- required
- Name
active- Kind
- parameter
- Type
unknown- Requirement
- required
- Name
return- Kind
- return value
- Type
boolean- Requirement
- n/a
queryTabbable
functiondeclare function queryTabbable(container: MinimalContainerLike): MinimalTabbableLike[];containerMinimalContainerLikereturnMinimalTabbableLike[]- Name
container- Kind
- parameter
- Type
MinimalContainerLike- Requirement
- required
- Name
return- Kind
- return value
- Type
MinimalTabbableLike[]- Requirement
- n/a
resolveFocusReturnTarget
functionRestores focus only when the candidate still has a callable `focus` function — `isConnected` alone is insufficient (a candidate might be a plain stand-in with no live DOM presence at all).
declare function resolveFocusReturnTarget(candidate: unknown): MinimalTabbableLike | null;candidateunknownreturnMinimalTabbableLike | null- Name
candidate- Kind
- parameter
- Type
unknown- Requirement
- required
- Name
return- Kind
- return value
- Type
MinimalTabbableLike | null- Requirement
- n/a
resolveInitialFocusTarget
functiondeclare function resolveInitialFocusTarget(container: MinimalContainerLike): MinimalTabbableLike;containerMinimalContainerLikereturnMinimalTabbableLike- Name
container- Kind
- parameter
- Type
MinimalContainerLike- Requirement
- required
- Name
return- Kind
- return value
- Type
MinimalTabbableLike- Requirement
- n/a
resolveTabTarget
functionAn active element outside the tracked set is treated as index -1: forwards enters at the first element, backwards enters at the last.
declare function resolveTabTarget(tabbable: readonly MinimalTabbableLike[], active: unknown, backwards: boolean): MinimalTabbableLike | null;tabbablereadonly MinimalTabbableLike[]activeunknownbackwardsbooleanreturnMinimalTabbableLike | null- Name
tabbable- Kind
- parameter
- Type
readonly MinimalTabbableLike[]- Requirement
- required
- Name
active- Kind
- parameter
- Type
unknown- Requirement
- required
- Name
backwards- Kind
- parameter
- Type
boolean- Requirement
- required
- Name
return- Kind
- return value
- Type
MinimalTabbableLike | null- Requirement
- n/a
TABBABLE_SELECTOR
valueexport declare const TABBABLE_SELECTOR: "a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])";trapFocus
functiondeclare function trapFocus(container: HTMLElement, options?: FocusTrapOptions): FocusTrapHandle;containerHTMLElementoptionsFocusTrapOptionsreturnFocusTrapHandle- Name
container- Kind
- parameter
- Type
HTMLElement- Requirement
- required
- Name
options- Kind
- parameter
- Type
FocusTrapOptions- Requirement
- optional
- Name
return- Kind
- return value
- Type
FocusTrapHandle- Requirement
- n/a
Framework adapters
Each panel keeps its adapter's public vocabulary. React compound exports, Vue composables, standalone Angular declarations, Svelte components, and Solid hooks stay native to their framework.
This entry is core-only. No framework adapter package ships for focus-trap yet — mount it through the vanilla API above.