Skip to content

Commit 84d0683

Browse files
authored
feat: add hideButtonOnActivate prop to hide play button after activation (#247)
* feat: add hideButtonOnActivate prop to remove play button after click * feat: add hideButtonOnActivate prop to hide play button after activation * feat: add hideButtonOnActivate prop to hide play button after activation
1 parent f90e8fe commit 84d0683

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

docs/docs/api-reference.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,20 @@ The `noCookie` prop is deprecated. Use `cookie` prop instead.
330330
/>
331331
```
332332

333+
#### `hideButtonOnActivate`
334+
335+
- **Type:** `boolean`
336+
- **Default:** `false`
337+
- **Description:** Hide play button after video is activated (iframe loaded)
338+
339+
```tsx
340+
<LiteYouTubeEmbed
341+
id="VIDEO_ID"
342+
title="Video"
343+
hideButtonOnActivate={true}
344+
/>
345+
```
346+
333347
---
334348

335349
## SEOData Type

src/lib/index.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,25 @@ describe("LiteYouTubeEmbed", () => {
357357
expect(ref.current!.tagName).toBe("IFRAME");
358358
});
359359

360+
test("hides play button after activation when hideButtonOnActivate is true", () => {
361+
render(<LiteYouTubeEmbed {...defaultProps} hideButtonOnActivate />);
362+
363+
// Button exists initially
364+
const playButton = screen.getByRole("button");
365+
expect(playButton).toBeInTheDocument();
366+
367+
// Click to activate
368+
fireEvent.click(playButton);
369+
370+
// Button should be removed
371+
const removedButton = screen.queryByRole("button");
372+
expect(removedButton).not.toBeInTheDocument();
373+
374+
// Iframe should be present
375+
const iframe = screen.getByTitle(defaultProps.title);
376+
expect(iframe).toBeInTheDocument();
377+
});
378+
360379
describe("Lazy loading", () => {
361380
test("renders with background-image by default (no lazy loading)", () => {
362381
const { container } = render(<LiteYouTubeEmbed {...defaultProps} />);

src/lib/index.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ export interface LiteYouTubeProps {
273273
* }}
274274
*/
275275
onPlaybackQualityChange?: (quality: string) => void;
276+
/**
277+
* Remove the play button element after the video is activated (iframe is added).
278+
* @default false
279+
*/
280+
hideButtonOnActivate?: boolean;
276281
}
277282

278283
/**
@@ -763,16 +768,18 @@ function LiteYouTubeEmbedComponent(
763768
{props.playlist && !iframe && (
764769
<div className="lty-playlist-icon" aria-hidden="true"></div>
765770
)}
766-
<button
767-
type="button"
768-
className={playerClassImp}
769-
aria-label={`${announceWatch} ${videoTitle}`}
770-
aria-hidden={iframe || undefined}
771-
tabIndex={iframe ? -1 : 0}
772-
onClick={addIframe}
773-
>
774-
<span className="lty-visually-hidden">{announceWatch}</span>
775-
</button>
771+
{!(props.hideButtonOnActivate && iframe) && (
772+
<button
773+
type="button"
774+
className={playerClassImp}
775+
aria-label={`${announceWatch} ${videoTitle}`}
776+
aria-hidden={iframe || undefined}
777+
tabIndex={iframe ? -1 : 0}
778+
onClick={addIframe}
779+
>
780+
<span className="lty-visually-hidden">{announceWatch}</span>
781+
</button>
782+
)}
776783
{iframe && (
777784
<iframe
778785
ref={ref}

0 commit comments

Comments
 (0)