menu: close when clicking outside in toggle mode

This commit is contained in:
bordun 2020-01-27 09:27:49 +01:00
parent 699078e089
commit 75f90e7455

View file

@ -122,6 +122,11 @@ class Menu extends Widget {
} else {
this.menu.classList.add('norelease')
this.toggleCloseHandler = (e)=>{
if (!this.opened || this.menu.contains(e.target)) return
this.close()
}
document.addEventListener('fast-click', this.toggleCloseHandler)
}
@ -310,6 +315,15 @@ class Menu extends Widget {
}
onRemove() {
if (this.getProp('toggle')) {
document.removeEventListener('fast-click', this.toggleCloseHandler)
}
super.onRemove()
}
}
Menu.dynamicProps = Menu.prototype.constructor.dynamicProps.concat(