Skip to content

Commit c9ac76c

Browse files
committed
Fix overriding iframe attributes - Astro doesn't merge attributes on HTML elements, so first attribute wins
Don't add the loading attribute to the iframe as we're using srcdoc Added JSDoc to improve editor experience
1 parent c15223b commit c9ac76c

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

YouTube.astro

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
---
2-
interface Props extends astroHTML.JSX.IframeHTMLAttributes {
2+
interface Props extends Omit<astroHTML.JSX.IframeHTMLAttributes, 'src' | 'srcdoc'> {
3+
/**
4+
* Pass `true` to embed using `www.youtube.com` instead of `www.youtube-nocookie.com`
5+
*/
36
cookie?: boolean
7+
/**
8+
* YouTube IFrame Player API parameters
9+
*
10+
* Defaults to `{autoplay: 1}`, additional parameters will be merged into the defaults
11+
* @see https://developers.google.com/youtube/player_parameters#Parameters
12+
*/
413
embedParams?: EmbedParams
14+
/**
15+
* `loading` attribute for the thumbnail `<img>`
16+
*
17+
* Defaults to `"lazy"`
18+
*/
19+
loading?: 'eager' | 'lazy'
20+
/**
21+
* Thumbnail image to use in the static embed
22+
*
23+
* Defaults to `"default"`, pass 1, 2 or 3 to use a screenshot from the video instead.
24+
*/
525
thumbnail?: Thumbnail
26+
/**
27+
* Thumbnail resolution
28+
*
29+
* Defaults to `"sd"` (640x480)
30+
*/
631
thumbnailRes?: ThumbnailRes
32+
/**
33+
* Title for the static embed
34+
*/
735
title: string
36+
/**
37+
* 11-digit YouTube video id
38+
*/
839
videoId: string
940
}
1041
@@ -77,13 +108,13 @@ let style = `<style>*{padding:0;margin:0;overflow:hidden}html,body{height:100%;b
77108
let srcdoc = `${style}<a href="${embedUrl}"><img src="${thumbnailUrl}" alt="${title}" loading="${loading}"><div class="gradient"></div><div class="top"><div class="title">${title}</div></div><div class="button">${playButtonSvg}</div></a>`
78109
---
79110
<iframe
111+
loading={loading}
112+
src={embedUrl}
113+
srcdoc={srcdoc}
114+
title={title}
115+
{...iframeAttributes}
80116
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
81117
allowfullscreen
82118
frameborder="0"
83-
loading={loading}
84119
style="width: 100%; aspect-ratio: 16/9;"
85-
title={title}
86-
{...iframeAttributes}
87-
src={embedUrl}
88-
srcdoc={srcdoc}
89120
/>

0 commit comments

Comments
 (0)