DEV Community

Discussion on: Focus Trapping - Trap focus inside an element

Collapse
 
maswerdna profile image
Samson Andrew

@david,
Setting up multiple events listeners on a document can have a performance impact on the document, therefore it is advisable to remove listeners when they are not in use. (It also helps to prevent memory leakage).

It can be used in this way:

    let signupModalCleaner

    modalControlButton.onclick = () => {
        if (open) {
            signupModalCleaner()
            open = false
        } else {
            signupModalCloser = loopFocus(config)
            open = true
    }
Enter fullscreen mode Exit fullscreen mode