@@ -33,11 +33,13 @@ function shouldUpdateVideo(prevProps, props) {
3333function filterResetOptions ( opts ) {
3434 return {
3535 ...opts ,
36+ height : 0 ,
37+ width : 0 ,
3638 playerVars : {
39+ ...opts . playerVars ,
3740 autoplay : 0 ,
3841 start : 0 ,
3942 end : 0 ,
40- ...opts . playerVars ,
4143 } ,
4244 } ;
4345}
@@ -52,7 +54,9 @@ function filterResetOptions(opts) {
5254 * @param {Object } props
5355 */
5456function shouldResetPlayer ( prevProps , props ) {
55- return ! isEqual ( filterResetOptions ( prevProps . opts ) , filterResetOptions ( props . opts ) ) ;
57+ return (
58+ prevProps . videoId !== props . videoId || ! isEqual ( filterResetOptions ( prevProps . opts ) , filterResetOptions ( props . opts ) )
59+ ) ;
5660}
5761
5862/**
@@ -62,7 +66,13 @@ function shouldResetPlayer(prevProps, props) {
6266 * @param {Object } props
6367 */
6468function shouldUpdatePlayer ( prevProps , props ) {
65- return prevProps . id !== props . id || prevProps . className !== props . className ;
69+ return (
70+ prevProps . id !== props . id ||
71+ prevProps . className !== props . className ||
72+ prevProps . opts . width !== props . opts . width ||
73+ prevProps . opts . height !== props . opts . height ||
74+ prevProps . title !== props . title
75+ ) ;
6676}
6777
6878class YouTube extends React . Component {
@@ -213,6 +223,12 @@ class YouTube extends React.Component {
213223 else iframe . removeAttribute ( 'id' ) ;
214224 if ( this . props . className ) iframe . setAttribute ( 'class' , this . props . className ) ;
215225 else iframe . removeAttribute ( 'class' ) ;
226+ if ( this . props . opts && this . props . opts . width ) iframe . setAttribute ( 'width' , this . props . opts . width ) ;
227+ else iframe . removeAttribute ( 'width' ) ;
228+ if ( this . props . opts && this . props . opts . height ) iframe . setAttribute ( 'height' , this . props . opts . height ) ;
229+ else iframe . removeAttribute ( 'height' ) ;
230+ if ( typeof this . props . title === 'string' ) iframe . setAttribute ( 'title' , this . props . title ) ;
231+ else iframe . setAttribute ( 'title' , 'YouTube video player' ) ;
216232 } ) ;
217233 } ;
218234
@@ -265,7 +281,7 @@ class YouTube extends React.Component {
265281 render ( ) {
266282 return (
267283 < div className = { this . props . containerClassName } >
268- < div id = { this . props . id } className = { this . props . className } ref = { this . refContainer } />
284+ < div id = { this . props . id } className = { this . props . className } ref = { this . refContainer } loading = { this . props . loading } />
269285 </ div >
270286 ) ;
271287 }
@@ -281,6 +297,11 @@ YouTube.propTypes = {
281297 className : PropTypes . string ,
282298 // custom class name for player container element
283299 containerClassName : PropTypes . string ,
300+ // custom title for the iFrame, see https://www.w3.org/TR/WCAG20-TECHS/H64.html
301+ title : PropTypes . string ,
302+
303+ // custom loading for player element
304+ loading : PropTypes . oneOf ( [ 'lazy' , 'eager' , 'auto' ] ) ,
284305
285306 // https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player
286307 opts : PropTypes . objectOf ( PropTypes . any ) ,
@@ -300,6 +321,7 @@ YouTube.defaultProps = {
300321 videoId : null ,
301322 id : null ,
302323 className : null ,
324+ loading : null ,
303325 opts : { } ,
304326 containerClassName : '' ,
305327 onReady : ( ) => { } ,
@@ -310,6 +332,7 @@ YouTube.defaultProps = {
310332 onStateChange : ( ) => { } ,
311333 onPlaybackRateChange : ( ) => { } ,
312334 onPlaybackQualityChange : ( ) => { } ,
335+ title : null ,
313336} ;
314337
315338export default YouTube ;
0 commit comments