feat(web): TrackRow div+role button with onPlay prop and + queue button

Outer <button> becomes <div role="button" tabindex="0"> with keyboard
handlers (Enter/Space) so a real <button> for + queue can nest without
invalid HTML. New optional onPlay prop overrides the default
playQueue(tracks, index); used by the search Tracks section to call
playRadio(track.id) instead. + queue button calls enqueueTrack and
stops propagation so the row click does not fire.
This commit is contained in:
2026-04-25 15:37:11 -04:00
parent 7eb051c6f7
commit 80b39f1713
2 changed files with 72 additions and 12 deletions
+41 -9
View File
@@ -1,25 +1,57 @@
<script lang="ts">
import type { TrackRef } from '$lib/api/types';
import { formatDuration } from '$lib/media/duration';
import { playQueue } from '$lib/player/store.svelte';
import { playQueue, enqueueTrack } from '$lib/player/store.svelte';
let { tracks, index }: { tracks: TrackRef[]; index: number } = $props();
type PlayHandler = (tracks: TrackRef[], index: number) => void;
let {
tracks,
index,
onPlay
}: { tracks: TrackRef[]; index: number; onPlay?: PlayHandler } = $props();
const track = $derived(tracks[index]);
function onClick() {
playQueue(tracks, index);
function activate() {
if (onPlay) onPlay(tracks, index);
else playQueue(tracks, index);
}
function onRowClick() {
activate();
}
function onRowKey(e: KeyboardEvent) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
activate();
}
}
function onAddClick(e: MouseEvent) {
e.stopPropagation();
enqueueTrack(track);
}
</script>
<button
type="button"
onclick={onClick}
class="grid w-full grid-cols-[32px_1fr_auto] items-center gap-4 px-3 py-2 text-left text-sm odd:bg-surface/50 hover:bg-surface focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent"
<div
role="button"
tabindex="0"
aria-label={track.title}
onclick={onRowClick}
onkeydown={onRowKey}
class="grid w-full cursor-pointer grid-cols-[32px_1fr_auto_auto] items-center gap-4 px-3 py-2 text-left text-sm odd:bg-surface/50 hover:bg-surface focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent"
>
<span class="text-right tabular-nums text-text-secondary">
{track.track_number ?? '—'}
</span>
<span class="truncate">{track.title}</span>
<button
type="button"
aria-label="Add to queue"
onclick={onAddClick}
class="rounded p-1 text-text-secondary hover:text-text-primary"
>+</button>
<span class="tabular-nums text-text-secondary">{formatDuration(track.duration_sec)}</span>
</button>
</div>