Skip to content

Commit ddd8207

Browse files
committed
Make child menu positioning more robust. More styling flexibility through variables.
1 parent 75aedf9 commit ddd8207

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mapbox-gl-contextmenu",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "A contextmenu plugin for Mapbox GL JS",
55
"type": "module",
66
"main": "./dist/index.cjs",
@@ -17,6 +17,7 @@
1717
},
1818
"scripts": {
1919
"dev": "vite",
20+
"dev:tailwind": "vite --config vite.config.tailwind.ts",
2021
"build": "tsc -p tsconfig.build.json && vite build",
2122
"preview": "vite preview",
2223
"docs": "typedoc"

src/components/ContextMenu/ContextMenu.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--context-menu-bg: #141414;
33
--context-menu-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
44
--context-menu-item-text-color: white;
5-
--context-menu-item-hover-bg: #444444;
5+
--context-menu-item-focus-bg: #444444;
66
--context-menu-item-active-bg: #2a2a2a;
77
--context-menu-item-disabled-opacity: 0.5;
88
--context-menu-separator-color: #505050;
@@ -27,7 +27,7 @@
2727
--context-menu-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
2828
--context-menu-item-font-size: 13px;
2929
--context-menu-item-text-color: black;
30-
--context-menu-item-hover-bg: #e8e8e8;
30+
--context-menu-item-focus-bg: #e8e8e8;
3131
--context-menu-item-active-bg: #f3f3f3;
3232
--context-menu-item-disabled-opacity: 0.5;
3333
--context-menu-separator-color: #e8e8e8;

src/components/ContextMenuItem/ContextMenuItem.module.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
align-items: center;
1818
gap: 12px;
1919
width: 100%;
20-
height: 28px;
20+
height: var(--context-menu-button-height, 28px);
2121
padding: 0px 4px 0px 12px;
2222
margin: 0;
2323
border: none;
24-
border-radius: 3px;
24+
border-radius: var(--context-menu-button-radius, 3px);
2525
background: none;
2626
color: var(--context-menu-item-text-color);
2727
text-align: left;
@@ -33,7 +33,7 @@
3333
font-size: var(--context-menu-item-font-size);
3434

3535
&.focused:not(:disabled):not(.focusedParent) {
36-
background-color: var(--context-menu-item-hover-bg);
36+
background-color: var(--context-menu-item-focus-bg);
3737
}
3838

3939
&.focusedParent:not(:disabled) {

src/components/ContextMenuSubmenu/ContextMenuSubmenu.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,14 @@ export default class ContextMenuSubmenu extends ContextMenuItem {
287287

288288
const submenuEl = this._submenu.menuElement;
289289
if (submenuEl) {
290-
// Get the first item's top padding to align submenu item with parent item
290+
// Calculate offset from menu top to first item top to align with parent
291291
const firstChild = submenuEl.firstElementChild as HTMLElement | null;
292-
const firstChildPaddingTop = firstChild
293-
? parseFloat(getComputedStyle(firstChild).paddingTop)
294-
: 0;
292+
const menuTop = submenuEl.getBoundingClientRect().top;
293+
const firstChildTop = firstChild
294+
? firstChild.getBoundingClientRect().top
295+
: menuTop;
295296

296-
y -= firstChildPaddingTop;
297+
y -= firstChildTop - menuTop;
297298

298299
const submenuWidth = submenuEl.offsetWidth;
299300
const submenuHeight = submenuEl.offsetHeight;

0 commit comments

Comments
 (0)