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
trappedis true. - Focuses the first focusable child on mount (
autoFocus) and restores focus to the previously focused element on unmount (restoreFocus). onEscapefires on Escape so you can close the surface.
API
FocusTrap
Keeps keyboard focus inside its children; used by overlays and available for custom ones.
| Prop | Type | Default | Description |
|---|---|---|---|
| autoFocus | boolean | true | Focus the first focusable element on mount. |
| className | string | — | |
| onEscape | ((event: KeyboardEvent) => void) | — | Called on Escape. |
| restoreFocus | boolean | true | Return focus to the previously focused element on unmount. |
| trapped | boolean | true | Trap Tab/Shift+Tab inside. |