mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
29 lines
767 B
JavaScript
29 lines
767 B
JavaScript
import ApplicationController from "./application_controller";
|
|
|
|
export default class extends ApplicationController {
|
|
reflex = "SelectorComponent";
|
|
|
|
connect() {
|
|
super.connect();
|
|
window.addEventListener("click", this.closeOnClickOutside);
|
|
this.computeItemsHeight();
|
|
}
|
|
|
|
disconnect() {
|
|
super.disconnect();
|
|
window.removeEventListener("click", this.closeOnClickOutside);
|
|
}
|
|
|
|
closeOnClickOutside = (event) => {
|
|
if (!this.element.contains(event.target)) {
|
|
this.stimulate(`${this.reflex}#close`, this.element);
|
|
}
|
|
};
|
|
|
|
computeItemsHeight = () => {
|
|
const items = this.element.querySelector(".selector-items");
|
|
const rect = items.getBoundingClientRect();
|
|
items.style.maxHeight = `calc(100vh - ${rect.height}px)`;
|
|
};
|
|
}
|