@tbremer/focus-trap
v0.0.2
Published
A small focus trap utility and React hook
Maintainers
Readme
focus-trap
Small focus trap utility and React hook.
Usage
import { createFocusTrap } from "@tbremer/focus-trap";
const el = document.getElementById("dialog")!;
const trap = createFocusTrap(el);
trap.attach();
// later
trap.detach();React hook
import { useRef } from "react";
import { useFocusTrap } from "@tbremer/focus-trap/react";
function Example() {
const ref = useRef<HTMLDivElement | null>(null);
useFocusTrap(ref.current);
return <div ref={ref}>...</div>;
}Development
Install dependencies and run tests:
npm ci
npm run test