From 8fc1fb6929bc3171cf8b00bfa9ebc9f8f51ccb83 Mon Sep 17 00:00:00 2001 From: Frank Stellmacher <171614930+Psychotoxical@users.noreply.github.com> Date: Thu, 21 May 2026 22:55:26 +0200 Subject: [PATCH] fix(album): bulk "add to playlist" no longer wipes the selection (#842) (#844) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The selection's outside-click handler ran on every mousedown outside the .tracklist, and the bulk-action toolbar is a DOM sibling of it. Clicking "Add to playlist" fired mousedown -> clearAll() -> inSelectMode=false, so the toolbar unmounted before the button's onClick could open the picker: selection vanished, no dialog. Skip the clear when the mousedown lands inside .album-track-toolbar (filter, add-to-playlist picker, clear button) — that UI belongs to the selection. Clicks elsewhere (header, empty page) still clear as before. --- src/hooks/useAlbumTrackListSelection.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooks/useAlbumTrackListSelection.ts b/src/hooks/useAlbumTrackListSelection.ts index 769825f1..a1ee91f3 100644 --- a/src/hooks/useAlbumTrackListSelection.ts +++ b/src/hooks/useAlbumTrackListSelection.ts @@ -20,7 +20,8 @@ interface UseAlbumTrackListSelectionResult { /** * Bulk selection + drag wiring for `AlbumTrackList`: * - Clears selection whenever the song list changes (album switch or - * filter applied) and on mousedown outside the tracklist. + * filter applied) and on mousedown outside the tracklist — but not when + * the click lands on the bulk-action toolbar, which belongs to the selection. * - `onToggleSelect` supports shift-click ranges anchored against the * last toggled row. * - `onDragStart` promotes a single-row drag into a multi-row drag when @@ -48,9 +49,14 @@ export function useAlbumTrackListSelection({ useEffect(() => { if (!inSelectMode) return; const handler = (e: MouseEvent) => { - if (tracklistRef.current && !tracklistRef.current.contains(e.target as Node)) { - useSelectionStore.getState().clearAll(); - } + const target = e.target as HTMLElement; + if (!tracklistRef.current || tracklistRef.current.contains(target)) return; + // The bulk-action toolbar (filter, add-to-playlist picker, clear button) + // renders outside the tracklist DOM but belongs to the selection — a + // mousedown there must not wipe the selection before the button's own + // click handler runs (otherwise "Add to playlist" clears and never opens). + if (target.closest('.album-track-toolbar')) return; + useSelectionStore.getState().clearAll(); }; document.addEventListener('mousedown', handler); return () => document.removeEventListener('mousedown', handler);