Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6b48fb3ac |
@@ -68,6 +68,29 @@ export class SeekBar extends LitElement {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* The clocks must not resize as they count.
|
||||
|
||||
Two things move them, and they need different answers. Digits in
|
||||
a proportional font are different widths, so 1:11 is narrower
|
||||
than 4:08 and the bar breathed once a second -- that is what
|
||||
tabular figures fix. The character *count* changes too, at the
|
||||
hundredth minute and whenever the right-hand clock is toggled to
|
||||
remaining and grows a minus sign, and a figure width cannot fix
|
||||
that -- so each clock also reserves the widest string this track
|
||||
can put in it. The budget is per track rather than a constant
|
||||
because reserving six characters on every track would push the
|
||||
slider in by a character at each end for nothing. */
|
||||
#seek-bar-container small,
|
||||
.time-toggle {
|
||||
font-variant-numeric: tabular-nums;
|
||||
flex: 0 0 auto;
|
||||
min-width: calc(var(--yj-clock-chars, 5) * 1ch);
|
||||
}
|
||||
|
||||
#seek-bar-container small {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.time-toggle {
|
||||
background: none;
|
||||
border: none;
|
||||
@@ -76,6 +99,9 @@ export class SeekBar extends LitElement {
|
||||
font: inherit;
|
||||
font-size: var(--wa-font-size-s, 0.875rem);
|
||||
cursor: pointer;
|
||||
/* One more for the minus sign the remaining form carries. */
|
||||
min-width: calc((var(--yj-clock-chars, 5) + 1) * 1ch);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.time-toggle:hover,
|
||||
@@ -219,8 +245,19 @@ export class SeekBar extends LitElement {
|
||||
: formatSeconds(this.trackLength);
|
||||
const rightTime = this.hasTrack ? rightLabel : '--:--';
|
||||
|
||||
// The widest string either clock can hold for *this* track. The
|
||||
// duration is the longest elapsed value there can be, so its length
|
||||
// is the budget; `--:--` is five, which is also the floor.
|
||||
const clockChars = Math.max(
|
||||
5,
|
||||
this.hasTrack ? formatSeconds(this.trackLength).length : 0,
|
||||
);
|
||||
|
||||
return html`
|
||||
<div id="seek-bar-container">
|
||||
<div
|
||||
id="seek-bar-container"
|
||||
style="--yj-clock-chars: ${clockChars}"
|
||||
>
|
||||
<small data-testid="elapsed-time">${elapsedTime}</small>
|
||||
<wa-slider
|
||||
label="Seek"
|
||||
|
||||
@@ -2,7 +2,6 @@ import { LitElement, html, css, nothing } from 'lit';
|
||||
import { customElement, property, state, query } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { designTokens } from '../../styles/tokens.css';
|
||||
import { srOnly } from '../../styles/sr-only.css';
|
||||
import {
|
||||
LookupReleaseGroup,
|
||||
BrowseReleases,
|
||||
@@ -290,7 +289,6 @@ export class ExploreAlbumDetails extends LitElement implements ContextMenuHost {
|
||||
designTokens,
|
||||
exploreLinkStyles,
|
||||
contextMenuStyles,
|
||||
srOnly,
|
||||
css`
|
||||
:host {
|
||||
display: flex;
|
||||
@@ -3035,21 +3033,11 @@ export class ExploreAlbumDetails extends LitElement implements ContextMenuHost {
|
||||
|
||||
/* ── Tracklist ── */
|
||||
|
||||
/**
|
||||
* The heading is there and is not drawn.
|
||||
*
|
||||
* A list of numbered titles with durations under an album's cover
|
||||
* does not need a word above it saying what it is — it was the
|
||||
* only thing on this page labelling something already obvious. But
|
||||
* the section is a landmark and the page's heading structure runs
|
||||
* through it, so what goes is the *ink*, not the element: a reader
|
||||
* jumping by heading still finds the tracklist.
|
||||
*/
|
||||
private renderTracklist() {
|
||||
if (this.loadingReleases) {
|
||||
return html`
|
||||
<section>
|
||||
<h3 class="sr-only">Tracklist</h3>
|
||||
<h3 class="section-header">Tracklist</h3>
|
||||
<div class="section-loading">Loading tracks\u2026</div>
|
||||
</section>
|
||||
`;
|
||||
@@ -3062,7 +3050,7 @@ export class ExploreAlbumDetails extends LitElement implements ContextMenuHost {
|
||||
if (!current) {
|
||||
return html`
|
||||
<section>
|
||||
<h3 class="sr-only">Tracklist</h3>
|
||||
<h3 class="section-header">Tracklist</h3>
|
||||
<div class="section-error">
|
||||
<wa-icon name="triangle-exclamation"></wa-icon>
|
||||
No release data available.
|
||||
@@ -3075,7 +3063,7 @@ export class ExploreAlbumDetails extends LitElement implements ContextMenuHost {
|
||||
if (tracks.length === 0) {
|
||||
return html`
|
||||
<section>
|
||||
<h3 class="sr-only">Tracklist</h3>
|
||||
<h3 class="section-header">Tracklist</h3>
|
||||
<div
|
||||
style="color: var(--yj-text-tertiary, #888); font-size: var(--yj-text-md)"
|
||||
>
|
||||
@@ -3091,7 +3079,7 @@ export class ExploreAlbumDetails extends LitElement implements ContextMenuHost {
|
||||
|
||||
return html`
|
||||
<section>
|
||||
<h3 class="sr-only">Tracklist</h3>
|
||||
<h3 class="section-header">Tracklist</h3>
|
||||
<div class="tracklist">
|
||||
${discNumbers.map((discNum) => {
|
||||
const discTracks = discMap.get(discNum) ?? [];
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/**
|
||||
* The tracklist's own heading.
|
||||
*
|
||||
* A list of numbered titles with durations, under the album's cover, is
|
||||
* the one thing on this page that did not need a word above it saying
|
||||
* what it was — "TRACKLIST" labelled the only thing already obvious.
|
||||
*
|
||||
* What goes is the *ink*, not the element. The section is a landmark
|
||||
* and the page's heading structure runs through it, so a reader moving
|
||||
* by heading still has to be able to find it, and it is hidden the way
|
||||
* `sr-only` hides things: `clip-path`, never `display: none`, which
|
||||
* would take it out of the accessibility tree along with the layout.
|
||||
*/
|
||||
import { describe, expect, it, beforeEach } from 'vitest';
|
||||
import type { LitElement } from 'lit';
|
||||
|
||||
import '@components/explore-album-details/explore-album-details';
|
||||
import { stub, flush, resetHarness } from '@test/support/harness';
|
||||
import { fixture, shadowAll } from '@test/support/render';
|
||||
|
||||
function track(n: number) {
|
||||
return {
|
||||
position: n,
|
||||
discNumber: 1,
|
||||
title: `Track ${n}`,
|
||||
length: 200000,
|
||||
mbid: `mbid-${n}`,
|
||||
inLibrary: true,
|
||||
};
|
||||
}
|
||||
|
||||
async function albumPage(): Promise<LitElement> {
|
||||
const el = await fixture<LitElement>('explore-album-details', {
|
||||
albumName: 'Glass Harbour',
|
||||
releaseGroupMBID: 'rg-1',
|
||||
});
|
||||
|
||||
Object.assign(el, {
|
||||
versionEntries: [
|
||||
{
|
||||
key: 'v1',
|
||||
label: '2019',
|
||||
sublabel: '2 tracks',
|
||||
tracks: [track(1), track(2)],
|
||||
},
|
||||
],
|
||||
selectedVersionKey: 'v1',
|
||||
loadingReleases: false,
|
||||
loadingInfo: false,
|
||||
});
|
||||
el.requestUpdate();
|
||||
await flush();
|
||||
await el.updateComplete;
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
const tracklistHeading = (el: LitElement) =>
|
||||
shadowAll(el, 'h3').find((h) => h.textContent?.trim() === 'Tracklist');
|
||||
|
||||
describe('the album tracklist heading', () => {
|
||||
beforeEach(() => {
|
||||
resetHarness();
|
||||
stub('library.Library.GetFilePathsByRecordingMBIDs', {});
|
||||
stub('library.Library.GetFilePathsByAlbums', {});
|
||||
stub('library.Library.GetAlbumTracks', []);
|
||||
stub('library.Library.GetAllLibrariesWithTrackCounts', []);
|
||||
stub('download.Service.ProviderKinds', []);
|
||||
stub('download.Service.ListProviders', []);
|
||||
stub('download.Service.ListDownloads', []);
|
||||
stub('download.Service.ListRequests', []);
|
||||
});
|
||||
|
||||
it('is still in the tree', async () => {
|
||||
expect(tracklistHeading(await albumPage())).toBeTruthy();
|
||||
});
|
||||
|
||||
it('takes up no room on the page', async () => {
|
||||
const heading = tracklistHeading(await albumPage())!;
|
||||
const box = heading.getBoundingClientRect();
|
||||
|
||||
expect(box.width).toBeLessThanOrEqual(1);
|
||||
expect(box.height).toBeLessThanOrEqual(1);
|
||||
// Hidden by clipping, not by removal: display:none and
|
||||
// visibility:hidden both take it out of the accessibility tree.
|
||||
expect(getComputedStyle(heading).display).not.toBe('none');
|
||||
expect(getComputedStyle(heading).visibility).not.toBe('hidden');
|
||||
});
|
||||
});
|
||||
@@ -227,6 +227,41 @@ describe('<seek-bar>', () => {
|
||||
expect(text(el, '[data-testid="remaining-time"]')).toBe('01:30');
|
||||
});
|
||||
|
||||
it('keeps the slider still as the clocks count', async () => {
|
||||
const el = await fixture('seek-bar');
|
||||
|
||||
emit(Events.TrackChanged, { ...TRACK, trackChangeId: 31 });
|
||||
await flush();
|
||||
await el.updateComplete;
|
||||
|
||||
const slider = () =>
|
||||
shadow(el, 'wa-slider')!.getBoundingClientRect();
|
||||
const before = slider();
|
||||
|
||||
// 1:11 against 4:08 is the reported jitter: different digits, and
|
||||
// in a proportional font different widths. Toggling the right-hand
|
||||
// clock is the other half -- the minus sign is a whole character.
|
||||
for (const positionSeconds of [8, 71, 88]) {
|
||||
emit(Events.PlaybackPositionChanged, {
|
||||
positionSeconds,
|
||||
trackLength: 90,
|
||||
trackChangeId: 31,
|
||||
seq: positionSeconds,
|
||||
playing: true,
|
||||
});
|
||||
await flush();
|
||||
await el.updateComplete;
|
||||
|
||||
expect(slider().width).toBeCloseTo(before.width, 1);
|
||||
expect(slider().left).toBeCloseTo(before.left, 1);
|
||||
}
|
||||
|
||||
await click(el, '[data-testid="remaining-time"]');
|
||||
await el.updateComplete;
|
||||
|
||||
expect(slider().width).toBeCloseTo(before.width, 1);
|
||||
});
|
||||
|
||||
it('renders the position the backend reports rather than its own count', async () => {
|
||||
const el = await fixture('seek-bar');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user