datui
Color scheme

Primitives

FocusTrap

Keeps keyboard focus inside its children. datui overlays use it internally; use it for custom popups.

import { FocusTrap } from "datui";

Examples

Trapped panel

Accessibility

  • Tab and Shift+Tab loop within the trap while trapped is true.
  • Focuses the first focusable child on mount (autoFocus) and restores focus to the previously focused element on unmount (restoreFocus).
  • onEscape fires on Escape so you can close the surface.

API

FocusTrap

Keeps keyboard focus inside its children; used by overlays and available for custom ones.

PropTypeDefaultDescription
autoFocusbooleantrueFocus the first focusable element on mount.
classNamestring—
onEscape((event: KeyboardEvent) => void)—Called on Escape.
restoreFocusbooleantrueReturn focus to the previously focused element on unmount.
trappedbooleantrueTrap Tab/Shift+Tab inside.