Fix TrackMenu z-index and edge clipping issues

- Use portal pattern to render menu in body (escapes stacking context)
- Increase z-index to 99999/100000 for menu/submenu
- Update click outside handler to work with portal
- Menu now properly appears above all track rows
This commit is contained in:
vicrodh committed 2026-01-16 06:56:36 -06:00
1 parent 9366388041
commit 24c9df3bce
1 file changed
+20 -4
+20 -4
View File
@@ -51,6 +51,18 @@
let menuStyle = $state(''); let menuStyle = $state('');
let submenuStyle = $state(''); let submenuStyle = $state('');
// Portal action - moves element to body to escape stacking context
function portal(node: HTMLElement) {
document.body.appendChild(node);
return {
destroy() {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
};
}
const hasPlayback = $derived(!!(onPlayNow || onPlayNext || onPlayLater)); const hasPlayback = $derived(!!(onPlayNow || onPlayNext || onPlayLater));
const hasLibrary = $derived(!!(onAddFavorite || onAddToPlaylist || onRemoveFromPlaylist)); const hasLibrary = $derived(!!(onAddFavorite || onAddToPlaylist || onRemoveFromPlaylist));
const hasShare = $derived(!!(onShareQobuz || onShareSonglink)); const hasShare = $derived(!!(onShareQobuz || onShareSonglink));
@@ -63,7 +75,11 @@
} }
function handleClickOutside(event: MouseEvent) { function handleClickOutside(event: MouseEvent) {
if (menuRef && !menuRef.contains(event.target as Node)) { const target = event.target as Node;
// Check if click is outside both the trigger container and the menu (which is in portal)
const isOutsideTrigger = menuRef && !menuRef.contains(target);
const isOutsideMenu = menuEl && !menuEl.contains(target);
if (isOutsideTrigger && isOutsideMenu) {
closeMenu(); closeMenu();
} }
} }
@@ -169,7 +185,7 @@
</button> </button>
{#if isOpen} {#if isOpen}
<div class="menu" bind:this={menuEl} style={menuStyle}> <div class="menu" bind:this={menuEl} style={menuStyle} use:portal>
{#if hasPlayback} {#if hasPlayback}
{#if onPlayNow} {#if onPlayNow}
<button class="menu-item" onclick={() => handleAction(onPlayNow)}> <button class="menu-item" onclick={() => handleAction(onPlayNow)}>
@@ -311,7 +327,7 @@
border-radius: 8px; border-radius: 8px;
padding: 2px 0; padding: 2px 0;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
z-index: 10000; z-index: 99999;
} }
.menu-item { .menu-item {
@@ -368,6 +384,6 @@
border-radius: 8px; border-radius: 8px;
padding: 2px 0; padding: 2px 0;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
z-index: 10001; z-index: 100000;
} }
</style> </style>