Add a check for map bounds in token menu

Removed hard coded dead zones in proxy token
This commit is contained in:
Mitchell McCaffrey
2020-04-14 09:41:10 +10:00
parent 6c12ab39f7
commit 7b7435f55a
4 changed files with 28 additions and 18 deletions

View File

@@ -107,6 +107,20 @@ function TokenMenu({ tokenClassName, onTokenChange }) {
},
{ once: true }
);
// Ensure menu is in bounds
const nodeRect = node.getBoundingClientRect();
const map = document.querySelector(".map");
const mapRect = map.getBoundingClientRect();
setMenuLeft((prevLeft) =>
Math.min(
mapRect.right - nodeRect.width,
Math.max(mapRect.left, prevLeft)
)
);
setMenuTop((prevTop) =>
Math.min(mapRect.bottom - nodeRect.height, prevTop)
);
}
}