Focus Trap
Traps keyboard focus inside a container. Small, boring, and load-bearing for everything modal.
v1.0.7@magic-spells/focus-trap
Usage
<button aria-controls="modal" aria-expanded="false"> Open Modal </button> <div id="modal" aria-hidden="true"> <focus-trap> <h2>Modal Content</h2> <input type="text" placeholder="Focusable input" /> <button>Focusable button</button> </focus-trap> </div>
About
A lightweight, customizable Web Component that traps keyboard focus within a container. Perfect for modals, dialogs, and any UI that requires constrained keyboard navigation.
Features
- No dependencies
- Lightweight (~2KB minified)
- Follows accessibility best practices
- Works with native keyboard navigation
- Handles Escape key to exit trap
- Uses aria attributes for accessibility
About, features, usage and options are taken from the package README.