mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Toggle is now controlled by the browser (and don't requires a reflex)
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import ApplicationController from "./application_controller";
|
||||
|
||||
export default class extends ApplicationController {
|
||||
reflex = "SelectorComponent";
|
||||
|
||||
connect() {
|
||||
super.connect();
|
||||
window.addEventListener("click", this.closeOnClickOutside);
|
||||
@@ -14,16 +12,26 @@ export default class extends ApplicationController {
|
||||
window.removeEventListener("click", this.closeOnClickOutside);
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.close();
|
||||
}
|
||||
|
||||
afterReflex() {
|
||||
this.computeItemsHeight();
|
||||
}
|
||||
|
||||
toggle = (event) => {
|
||||
event.preventDefault();
|
||||
this.element.querySelector(".selector").classList.toggle("selector-close");
|
||||
};
|
||||
|
||||
// Private
|
||||
closeOnClickOutside = (event) => {
|
||||
if (
|
||||
!this.element.contains(event.target) &&
|
||||
this.isVisible(this.element.querySelector(".selector-wrapper"))
|
||||
) {
|
||||
this.stimulate(`${this.reflex}#close`, this.element);
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,4 +45,8 @@ export default class extends ApplicationController {
|
||||
const style = window.getComputedStyle(element);
|
||||
return style.display !== "none" && style.visibility !== "hidden";
|
||||
};
|
||||
|
||||
close = () => {
|
||||
this.element.querySelector(".selector").classList.add("selector-close");
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user