bit Bheadless

FocusTrap

A low-level component that traps keyboard focus within a container. Used internally by Dialog but also useful standalone for custom modal-like patterns.

Implementation: CSS Tailwind

Basic Focus Trap

Toggle the trap on and off. While active, pressing Tab and Shift+Tab cycles through the focusable elements inside the container without escaping to the rest of the page. Focus is automatically moved to the first focusable element when the trap activates, and restored to the previously-focused element when it deactivates.

Focus is free inside this box.

Slide-over panel

A common use case: a slide-over panel that traps focus while visible. The trap activates when the panel opens and deactivates when it closes, returning focus to the trigger button.

Multiple focusable regions

Demonstrates that only the active trap captures focus. Toggle between two regions — only the enabled one traps Tab navigation.

Region A
Region B
An unhandled error has occurred. Reload 🗙