fix: align calc menus with trigger width
This commit is contained in:
@@ -357,6 +357,7 @@ function toggleModeMenu() {
|
||||
modeMenuEl = document.createElement('div');
|
||||
modeMenuEl.className = 'mode-menu';
|
||||
modeMenuEl.style.top = `${rect.bottom + 6 + window.scrollY}px`;
|
||||
modeMenuEl.style.minWidth = `${rect.width}px`;
|
||||
modeOptions.forEach((mode) => {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
@@ -370,9 +371,7 @@ function toggleModeMenu() {
|
||||
modeMenuEl.appendChild(button);
|
||||
});
|
||||
document.body.appendChild(modeMenuEl);
|
||||
const menuRect = modeMenuEl.getBoundingClientRect();
|
||||
const maxLeft = Math.max(8, window.innerWidth - menuRect.width - 8);
|
||||
modeMenuEl.style.left = `${Math.max(8, Math.min(maxLeft, rect.left + window.scrollX))}px`;
|
||||
modeMenuEl.style.left = `${rect.left + window.scrollX}px`;
|
||||
}
|
||||
|
||||
modeButton.addEventListener('click', (event) => {
|
||||
@@ -451,6 +450,7 @@ function toggleConstMenu() {
|
||||
constMenuEl = document.createElement('div');
|
||||
constMenuEl.className = 'mode-menu';
|
||||
constMenuEl.style.top = `${rect.bottom + 6 + window.scrollY}px`;
|
||||
constMenuEl.style.minWidth = `${rect.width}px`;
|
||||
const availableConstants = calc.listConstants();
|
||||
const keys = [...constantOrder, ...Object.keys(availableConstants).filter((name) => !constantOrder.includes(name))];
|
||||
keys.forEach((name) => {
|
||||
@@ -472,9 +472,7 @@ function toggleConstMenu() {
|
||||
constMenuEl.appendChild(button);
|
||||
});
|
||||
document.body.appendChild(constMenuEl);
|
||||
const menuRect = constMenuEl.getBoundingClientRect();
|
||||
const desiredLeft = rect.right + window.scrollX - menuRect.width;
|
||||
constMenuEl.style.left = `${Math.max(8, desiredLeft)}px`;
|
||||
constMenuEl.style.left = `${rect.left + window.scrollX}px`;
|
||||
}
|
||||
|
||||
constButton.addEventListener('click', (event) => {
|
||||
|
||||
Reference in New Issue
Block a user