Navigated to /docs/ui/components/focus-trap

FocusTrap

Keyboard focus containment helper for overlays.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import the component from its dedicated entry point to keep the dependency and generated bundle explicit.

TSX
tsximport { FocusTrap } from "@tavojs/ui/focus-trap";

Normal Tavo.js applications load component styles through the Tavo.js UI plugin. If the application manages component CSS manually, also import @tavojs/ui/css/focus-trap.

When to use

Use it when

Use `FocusTrap` to keep keyboard focus inside a subtree

Choose something else when

Avoid FocusTrap when using feedback components as primary page layout.

Examples

FocusTrap example

TSX
tsximport { FocusTrap } from "@tavojs/ui/focus-trap";

export function FocusTrapExample1() {
  const content = "Keyboard-contained content";
  return (
    <>
      <FocusTrap active>{content}</FocusTrap>
    </>
  );
}

Common props and defaults

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
activeboolean

Configures active for this component.

Complete TypeScript API

Import from @tavojs/ui/focus-trap. Published exports: FocusTrap, FocusTrapProps.

FocusTrapProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by FocusTrap.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by FocusTrap.

idstring

No

Inherited id attribute accepted by FocusTrap.

rolestring

No

Inherited role attribute accepted by FocusTrap.

styleRecord<string, unknown>

No

Inherited style attribute accepted by FocusTrap.

titlestring

No

Inherited title attribute accepted by FocusTrap.

tabIndexnumber

No

Inherited tabIndex attribute accepted by FocusTrap.

hiddenboolean

No

Inherited hidden attribute accepted by FocusTrap.

disabledboolean

No

Inherited disabled attribute accepted by FocusTrap.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by FocusTrap.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by FocusTrap.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by FocusTrap.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by FocusTrap.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by FocusTrap.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by FocusTrap.

activeboolean

No

Configures active for this component.

State ownership and DOM target

ConcernContract
StateNo component state contract is exposed; the application owns the rendered content and surrounding behavior.
DOM targetPublic passthrough props target the component root. Treat nested elements and private class names as implementation details.

Anatomy and related components

This component exposes one public component root rather than a compound member API.

Limitations

Avoid FocusTrap when using feedback components as primary page layout.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

Traps `Tab` and `Shift+Tab` within focusable descendants.

  • Traps `Tab` and `Shift+Tab` within focusable descendants.

Component status

ContractCurrent value
Maturitystable
Categoryfeedback
Component import@tavojs/ui/focus-trap
Explicit CSS import@tavojs/ui/css/focus-trap
PreviewInteractive preview available on this page