Defocuser
addElement
To use the Defocuser all you have to do is create an instance of the Defocuser
class and then
call the addElement
method. This method takes 5 parameters:
el
- that is the root of your dropdownphase
- that should be eithercapture
orbubbling
callback
- that is the callback called when the situation that the user clicked outsidestopPropagation
- when handling thekeydown
orclick
events calle.stopPropagation()
(default:false
)preventDefault
- when handling thekeydown
orclick
events calle.preventDefault()
(default:false
)
setSecondaryElement
If for some reason there is an additional element (like an input or label that you use to toggle
your dropdow) Defocuser
has you covered with the setSecondaryElement
method that takes
the following parameters:
el
- that is the root of your dropdown (primary)secondary
- that additional element to be taken into account when checking if the actioned element is inside or outside of the dropdown
Remarks
Defocuser
internally uses MutationObserver
to detect when the element has been removed from
the DOM. So you should physically remove the element to clean things up.