A library to help trap the focus of keyboard inside an element.
Warn: Don't trap the users keyboard unless the usecase is so, it might be a usability issue rather than providing accessibility
Refer to https://youtu.be/JS68faEUduk?t=10m56s
You'r usecase might be suited by inert https://youtu.be/fGLp_gfMMGU
Using the TrapKeyboard
class:
const trap = new TrapKeyboard(root, options);
// Call the 'trap' method
trap.trap();
root
: Element to trap keyboard inside of.
options
: MutationObserverInit object for responding to changes on root and child elements.
To untrap the keyboard, just call the unTrap
method on the instance:
trap.unTrap();