@pukanito/focustrap
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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:

  1. focusable - access the underlying Focusable.

FocusTrap has the following methods:

  1. uninstall() - uninstalls the focus trap.

Package Sidebar

Install

npm i @pukanito/focustrap

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.45 kB

Total Files

8

Last publish

Collaborators

  • pukanito