Commit 867aa9c8 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Smooth player transitions, better lyrics view, accessibility pass

- FullPlayer and NowPlayingBar now animate in/out (slide + fade) via
  a shared useMountTransition hook instead of snapping in/out, with
  motion-reduce fallbacks for users who've asked for less motion.
- Lyrics moved from a small icon toggle into a proper Cover/Lyrics
  tab switcher (real tablist/tab/tabpanel roles, arrow-key navigation,
  crossfade between panels), with larger type, a scroll fade mask, and
  a real empty state for tracks with no lyrics.
- FullPlayer is now a proper dialog: aria-modal, focus moves to it on
  open and back to the control that opened it on close, Escape closes
  it, and background scroll is locked while it's open.
- Seek bar reskinned as a real <input type="range"> (keeps native
  keyboard/pointer/AT support) with a progress-fill gradient and a
  hover-revealed thumb, plus aria-valuetext with formatted times.
- Added a visible focus-visible ring to the shared Button component
  and to the player's own raw buttons (WCAG 2.4.7).
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 54d3c423
Pipeline #1045 failed with stage
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { PlayerProvider, usePlayer, type PlayableSong } from '../context/PlayerContext'
import { NowPlayingBar } from './NowPlayingBar'
import { FullPlayer } from './FullPlayer'
import * as streamApi from '../api/stream'
const SONG: PlayableSong = {
id: 1,
title: 'Test Song',
artist: 'Test Artist',
album: 'Test Album',
lyrics: 'Line one\nLine two',
}
function Probe() {
const { toggle } = usePlayer()
return <button onClick={() => toggle(SONG)}>Start Playback</button>
}
function renderPlayer() {
return render(
<PlayerProvider>
<Probe />
<NowPlayingBar />
<FullPlayer />
</PlayerProvider>,
)
}
describe('FullPlayer', () => {
afterEach(() => {
vi.restoreAllMocks()
})
it('opens from the mini player, focuses the minimize button, and shows lyrics on the Lyrics tab', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ })
await userEvent.click(openButton)
await screen.findByRole('dialog', { name: /Now playing: Test Song by Test Artist/ })
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
expect(screen.getByRole('tab', { name: /Cover/ })).toHaveAttribute('aria-selected', 'true')
await userEvent.click(screen.getByRole('tab', { name: /Lyrics/ }))
expect(screen.getByRole('tab', { name: /Lyrics/ })).toHaveAttribute('aria-selected', 'true')
expect(screen.getByText(/Line one/)).toBeInTheDocument()
})
it('shows a clear empty state when a track has no lyrics', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
function ProbeNoLyrics() {
const { toggle } = usePlayer()
return <button onClick={() => toggle({ ...SONG, lyrics: null })}>Start Playback</button>
}
render(
<PlayerProvider>
<ProbeNoLyrics />
<NowPlayingBar />
<FullPlayer />
</PlayerProvider>,
)
await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ })
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
await userEvent.click(screen.getByRole('tab', { name: /Lyrics/ }))
expect(screen.getByText('No lyrics available for this track.')).toBeInTheDocument()
})
it('closes on Escape and returns focus to the control that opened it', async () => {
vi.spyOn(streamApi, 'fetchStreamUrl').mockResolvedValue('blob:fake-url')
renderPlayer()
await userEvent.click(screen.getByText('Start Playback'))
const openButton = await screen.findByRole('button', { name: /Open player/ })
await userEvent.click(openButton)
await waitFor(() => expect(screen.getByRole('button', { name: 'Minimize player' })).toHaveFocus())
await userEvent.keyboard('{Escape}')
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
await waitFor(() => expect(openButton).toHaveFocus())
})
})
This diff is collapsed.
......@@ -66,7 +66,7 @@ export function Layout({ title, children }: { title: string; children: ReactNode
</header>
<main
className={`mx-auto max-w-2xl px-4 py-6 sm:px-6 sm:py-8 ${currentSong ? 'pb-40 sm:pb-24' : 'pb-24 sm:pb-8'}`}
className={`mx-auto max-w-2xl px-4 py-6 transition-[padding] duration-300 ease-out motion-reduce:transition-none sm:px-6 sm:py-8 ${currentSong ? 'pb-40 sm:pb-24' : 'pb-24 sm:pb-8'}`}
>
<h1 className="mb-6 text-xl font-semibold tracking-tight">{title}</h1>
{children}
......
import { useEffect, useRef } from 'react'
import { Music2, Pause, Play } from 'lucide-react'
import { usePlayer } from '../context/PlayerContext'
import { useMountTransition } from '../hooks/useMountTransition'
/** Persistent player bar, visible on every page while a song is loaded (like Spotify's
* bottom bar) - stacked above the mobile tab bar (bottom-14 ≈ its height) since both are
* fixed to the viewport bottom; sits directly at the bottom on sm+ where there's no tab bar. */
export function NowPlayingBar() {
const { currentSong, isPlaying, isLoading, toggle, expand } = usePlayer()
const { currentSong, isPlaying, isLoading, isExpanded, toggle, expand } = usePlayer()
const { mounted, visible } = useMountTransition(!!currentSong, 300)
const openButtonRef = useRef<HTMLButtonElement>(null)
const wasExpandedRef = useRef(isExpanded)
if (!currentSong) return null
// FullPlayer moves focus to its own close button on open; when it closes again, hand
// keyboard focus back to the control that opened it instead of dropping it to <body>.
useEffect(() => {
if (wasExpandedRef.current && !isExpanded) {
openButtonRef.current?.focus()
}
wasExpandedRef.current = isExpanded
}, [isExpanded])
if (!mounted || !currentSong) return null
return (
<div
className="fixed inset-x-0 bottom-14 z-20 border-t border-neutral-800 bg-neutral-900/95 backdrop-blur sm:bottom-0"
className={`fixed inset-x-0 bottom-14 z-20 border-t border-neutral-800 bg-neutral-900/95 backdrop-blur transition-all duration-300 ease-out motion-reduce:transition-none sm:bottom-0 ${
visible ? 'translate-y-0 opacity-100' : 'translate-y-full opacity-0'
}`}
style={{ paddingBottom: 'env(safe-area-inset-bottom)' }}
>
<div className="mx-auto flex max-w-2xl items-center gap-3 px-4 py-2.5 sm:px-6">
{/* Separate <button> from the play/pause control below - two sibling buttons rather
than nesting one inside the other, which isn't valid HTML. */}
<button
ref={openButtonRef}
onClick={expand}
aria-label={`Open player - ${currentSong.title}`}
className="flex min-w-0 flex-1 items-center gap-3 text-left"
className="flex min-w-0 flex-1 items-center gap-3 rounded-lg text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
>
{currentSong.coverart ? (
<img src={currentSong.coverart} alt="" className="h-10 w-10 shrink-0 rounded-md object-cover" />
......@@ -38,7 +55,7 @@ export function NowPlayingBar() {
onClick={() => toggle(currentSong)}
disabled={isLoading}
aria-label={isPlaying ? 'Pause' : 'Play'}
className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-neutral-800 text-white transition-transform active:scale-90 disabled:opacity-50"
className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-neutral-800 text-white transition-transform duration-150 ease-out active:scale-90 disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400"
>
{isLoading ? (
<span className="h-3.5 w-3.5 animate-spin rounded-full border-2 border-neutral-600 border-t-white" />
......
......@@ -27,7 +27,7 @@ export const Button = forwardRef<HTMLButtonElement, Props>(function Button(
return (
<button
ref={ref}
className={`inline-flex items-center justify-center gap-1.5 rounded-full font-medium transition-all duration-150 ease-out active:scale-[0.96] disabled:cursor-not-allowed disabled:opacity-40 disabled:active:scale-100 ${VARIANT_CLASSES[variant]} ${SIZE_CLASSES[size]} ${className}`}
className={`inline-flex items-center justify-center gap-1.5 rounded-full font-medium transition-all duration-150 ease-out active:scale-[0.96] disabled:cursor-not-allowed disabled:opacity-40 disabled:active:scale-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950 ${VARIANT_CLASSES[variant]} ${SIZE_CLASSES[size]} ${className}`}
{...props}
/>
)
......
import { useEffect, useState } from 'react'
/** Keeps a component mounted long enough to play its exit transition instead of vanishing
* instantly. Flip `active` on/off and drive enter/exit CSS classes off `visible`; `mounted`
* gates whether to render at all - it stays true for `durationMs` after `active` goes false so
* the exit transition has time to finish before the DOM node (and its focusable children) are
* actually removed. */
export function useMountTransition(active: boolean, durationMs: number) {
const [mounted, setMounted] = useState(active)
const [visible, setVisible] = useState(false)
useEffect(() => {
if (active) {
setMounted(true)
// Mounting with the "hidden" classes already applied, then flipping to visible one
// frame later, is what makes the enter transition actually animate instead of
// snapping straight to its end state.
const raf = requestAnimationFrame(() => setVisible(true))
return () => cancelAnimationFrame(raf)
}
setVisible(false)
const timeout = setTimeout(() => setMounted(false), durationMs)
return () => clearTimeout(timeout)
}, [active, durationMs])
return { mounted, visible }
}
......@@ -23,3 +23,64 @@
transform: translateX(300%);
}
}
/* Reskin the native range input used for the player's seek bar - kept as a real
<input type="range"> rather than a custom div-based slider so keyboard stepping, pointer
dragging, and screen reader announcements all come for free from the platform. The filled
portion is painted via an inline background gradient (see FullPlayer.tsx); this stylesheet
only strips the default track chrome and styles the thumb. */
.seek-range {
-webkit-appearance: none;
appearance: none;
height: 4px;
border-radius: 9999px;
background-color: transparent;
}
.seek-range::-webkit-slider-runnable-track {
height: 4px;
border-radius: 9999px;
}
.seek-range::-moz-range-track {
height: 4px;
border-radius: 9999px;
background: transparent;
}
.seek-range::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 13px;
height: 13px;
margin-top: -4.5px;
border-radius: 9999px;
background: white;
opacity: 0;
transition: opacity 150ms ease-out;
}
.seek-range::-moz-range-thumb {
width: 13px;
height: 13px;
border: none;
border-radius: 9999px;
background: white;
opacity: 0;
transition: opacity 150ms ease-out;
}
.seek-range:hover::-webkit-slider-thumb,
.seek-range:focus-visible::-webkit-slider-thumb {
opacity: 1;
}
.seek-range:hover::-moz-range-thumb,
.seek-range:focus-visible::-moz-range-thumb {
opacity: 1;
}
.seek-range:focus-visible {
outline: 2px solid #34d399;
outline-offset: 4px;
border-radius: 9999px;
}
.seek-range:disabled::-webkit-slider-thumb {
display: none;
}
.seek-range:disabled::-moz-range-thumb {
display: none;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment