Skip to content

Commit

Permalink
fix(audio-player): hide menu when playback rates are not set (VIV-1845)…
Browse files Browse the repository at this point in the history
… (#1815)
  • Loading branch information
rachelbt authored Jul 3, 2024
1 parent 1faa01b commit f0e32d1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
16 changes: 9 additions & 7 deletions libs/components/src/lib/audio-player/audio-player.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,26 +496,26 @@ describe('vwc-audio-player', () => {
expect(element.playbackRates).toBe(null);
});

it('should hide playbackRates button as default', async () => {
expect(getPlaybackRatesButton()).toBeNull();
it('should hide playbackRates menu as default', async () => {
expect(getPlaybackRatesMenuElement()).toBeNull();
});

it('should hide playbackRates button when attribute is removed', async () => {
it('should hide playbackRates menu when attribute is removed', async () => {
element.playbackRates = DEFAULT_PLAYBACK_RATES;
await elementUpdated(element);
element.removeAttribute('playback-rates');
await elementUpdated(element);

expect(getPlaybackRatesButton()).toBeNull();
expect(getPlaybackRatesMenuElement()).toBeNull();
});

it('should hide playbackRates button when empty', async () => {
it('should hide playbackRates menu when empty', async () => {
element.playbackRates = DEFAULT_PLAYBACK_RATES;
await elementUpdated(element);
element.playbackRates = '';
await elementUpdated(element);

expect(getPlaybackRatesButton()).toBeNull();
expect(getPlaybackRatesMenuElement()).toBeNull();
});

it('should set class playback on base when playbackRates is truthy', async () => {
Expand Down Expand Up @@ -556,7 +556,9 @@ describe('vwc-audio-player', () => {
);
});

it('should start with a closed menu item', () => {
it('should start with a closed menu item', async () => {
element.playbackRates = DEFAULT_PLAYBACK_RATES;
await elementUpdated(element);
expect(getPlaybackRatesMenuElement()?.hasAttribute('open')).toBe(false);
});

Expand Down
29 changes: 15 additions & 14 deletions libs/components/src/lib/audio-player/audio-player.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,30 +163,31 @@ export const AudioPlayerTemplate: (
${when((x) => !x.notime, renderTimestamp())}
</div>
${renderSlider(context)}
<${menuTag} class="playback-rates" trigger="auto" placement="top-start" auto-dismiss>
${when(
(x) => Boolean(x.playbackRates),
html`<${buttonTag} id="playback-open-button"
${when(
(x) => Boolean(x.playbackRates),
html`
<${menuTag} class="playback-rates" trigger="auto" placement="top-start" auto-dismiss id="playback-menu">
<${buttonTag} id="playback-open-button"
class="playback-button"
slot="anchor"
icon="playback-speed-line"
aria-label="play back rates"
size='condensed'
connotation="${(x) => x.connotation}"
?disabled="${(x) => x.disabled || !x.duration}"
></${buttonTag}>`
)}
></${buttonTag}>
${repeat(
(x) =>
x.playbackRates ? getPlaybackRatesArray(x.playbackRates) : [],
(x) => getPlaybackRatesArray(x.playbackRates),
html<number>`<${menuItemTag} @click="${handlePlaybackRateClick}"
role="menuitemradio"
class="playback-rate"
text="${(x) => x}"
check-appearance="tick-only"
?checked="${isMenuItemChekced}"></${menuItemTag}>`
role="menuitemradio"
class="playback-rate"
text="${(x) => x}"
check-appearance="tick-only"
?checked="${isMenuItemChekced}"></${menuItemTag}>`
)}
</${menuTag}>
</${menuTag}>`
)}
</div>
</div>`;
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0e32d1

Please sign in to comment.