mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Only send close reflex if element is actually visible
This commit is contained in:
@@ -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";
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user