Only send close reflex if element is actually visible

This commit is contained in:
Jean-Baptiste Bellet
2022-03-24 09:44:49 +01:00
parent 265b4823a7
commit 22d13621f4

View File

@@ -14,8 +14,15 @@ export default class extends ApplicationController {
window.removeEventListener("click", this.closeOnClickOutside);
}
afterReflex() {
this.computeItemsHeight();
}
closeOnClickOutside = (event) => {
if (!this.element.contains(event.target)) {
if (
!this.element.contains(event.target) &&
this.isVisible(this.element.querySelector(".selector-wrapper"))
) {
this.stimulate(`${this.reflex}#close`, this.element);
}
};
@@ -25,4 +32,9 @@ export default class extends ApplicationController {
const rect = items.getBoundingClientRect();
items.style.maxHeight = `calc(100vh - ${rect.height}px)`;
};
isVisible = (element) => {
const style = window.getComputedStyle(element);
return style.display !== "none" && style.visibility !== "hidden";
};
}