mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
Add a onClickOutside behavior that close the component if clicked outside Selector component doesn't handle its state but receive props from parent u
19 lines
493 B
JavaScript
19 lines
493 B
JavaScript
import ApplicationController from "./application_controller";
|
|
|
|
export default class extends ApplicationController {
|
|
connect() {
|
|
super.connect();
|
|
window.addEventListener("click", this.closeOnClickOutside);
|
|
}
|
|
disconnect() {
|
|
super.disconnect();
|
|
window.removeEventListener("click", this.closeOnClickOutside);
|
|
}
|
|
|
|
closeOnClickOutside = (event) => {
|
|
if (!this.element.contains(event.target)) {
|
|
this.stimulate("SelectorComponent#close", this.element);
|
|
}
|
|
};
|
|
}
|