@pukanito/focustrap
v1.0.0
Published
Trap keyboard focus inside an element
Downloads
4
Maintainers
Readme
focustrap
This library was generated with Nx.
Keeps focus trapped inside a HTMLElement when navigating with the keyboard.
Available on npmjs.com.
Usage
In package.json
add a dependency to 'focustrap' and 'focusable':
{
"dependencies": {
"@pukanito/focustrap": "1.0.0",
"@pukanito/focusable": "1.0.0"
}
}
Use FocusTrap
:
import { FocusTrap } from '@pukanito/focustrap';
const container = document.querySelector('...')!;
const focusTrap = new FocusTrap(container);
/* Focus trapped inside the container */
focusTrap.uninstall()
/* Focus no longer trapped */
container
: The element where to trap focus.
Properties
FocusTrap
has the following properties:
focusable
- access the underlyingFocusable
.
FocusTrap
has the following methods:
uninstall()
- uninstalls the focus trap.