ComponentformZero dependenciesZero dependencies
Focus Trap
Pure TypeScript focus trapping helpers for accessible overlays: getFocusable and trapFocus.
Preview
Live Preview
Tab cycles inside
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add focus-trapOr install the full npm package:
npm install bigbulluiUsage
Open in StackBlitzimport { trapFocus } from "@/components/ui/lib/focus-trap";
onKeyDown={(e) => { if (e.key === "Tab") trapFocus(containerRef.current, e.nativeEvent); }}Usage guidance
Use Focus Trap when a ticket stub surface needs Pure TypeScript focus trapping helpers for accessible overlays: getFocusable and trapFocus. Keep props minimal and prefer composition with sibling stubs.
Avoid Focus Trap for long form flows or dense data grids where a dedicated layout block fits better.
Props
| Prop | Type | Description |
|---|---|---|
| container | HTMLElement | Trap boundary element (trapFocus arg, required). |
| event | KeyboardEvent | Native Tab key event (trapFocus arg, required). |