fix(ui): render track menu caret reliably

cx
This commit is contained in:
vicrodh committed 2026-01-22 12:02:49 -06:00
1 parent e45d899437
commit 96b31f6e25
1 file changed
+13 -4
+13 -4
View File
@@ -68,6 +68,7 @@
const menuId = allocateTrackMenuId(); const menuId = allocateTrackMenuId();
let isOpen = $state(false); let isOpen = $state(false);
let openSide = $state<'left' | 'right'>('left');
let shareOpen = $state(false); let shareOpen = $state(false);
let downloadOpen = $state(false); let downloadOpen = $state(false);
let menuRef: HTMLDivElement | null = null; let menuRef: HTMLDivElement | null = null;
@@ -143,7 +144,7 @@
const leftPreferred = triggerRect.left - menuRect.width - gap; const leftPreferred = triggerRect.left - menuRect.width - gap;
const rightPreferred = triggerRect.right + gap; const rightPreferred = triggerRect.right + gap;
let openSide: 'left' | 'right' = 'left'; openSide = 'left';
let left = leftPreferred; let left = leftPreferred;
if (left < padding && rightPreferred + menuRect.width <= window.innerWidth - padding) { if (left < padding && rightPreferred + menuRect.width <= window.innerWidth - padding) {
openSide = 'right'; openSide = 'right';
@@ -169,8 +170,6 @@
const arrowTop = Math.max(arrowPadding, Math.min(menuRect.height - arrowPadding, arrowTopUnclamped)); const arrowTop = Math.max(arrowPadding, Math.min(menuRect.height - arrowPadding, arrowTopUnclamped));
menuStyle = `left: ${left}px; top: ${top}px; --arrow-top: ${arrowTop}px;`; menuStyle = `left: ${left}px; top: ${top}px; --arrow-top: ${arrowTop}px;`;
menuEl?.classList.toggle('open-left', openSide === 'left');
menuEl?.classList.toggle('open-right', openSide === 'right');
} }
async function setSubmenuPosition() { async function setSubmenuPosition() {
@@ -248,6 +247,9 @@
$effect(() => { $effect(() => {
if (isOpen) { if (isOpen) {
// Ensure position + openSide classes are applied even if the initial openMenu()
// call returns early due to timing.
setMenuPosition();
document.addEventListener('mousedown', handleClickOutside); document.addEventListener('mousedown', handleClickOutside);
const handleResize = () => setMenuPosition(); const handleResize = () => setMenuPosition();
const handleScroll = () => { const handleScroll = () => {
@@ -291,7 +293,14 @@
</button> </button>
{#if isOpen} {#if isOpen}
<div class="menu" bind:this={menuEl} style={menuStyle} use:portal> <div
class="menu"
class:open-left={openSide === 'left'}
class:open-right={openSide === 'right'}
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)}>