Skip to content

Commit

Permalink
Accessibility Improvements for PE Pattern (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjehl authored Aug 10, 2024
1 parent 217b3cd commit 571be5d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lite-yt-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,23 @@ class LiteYTEmbed extends HTMLElement {

this.addNoscriptIframe();

playBtnEl.removeAttribute('href');
// for the PE pattern, change anchor's semantics to button
if(playBtnEl.nodeName === 'A'){
playBtnEl.removeAttribute('href');
playBtnEl.setAttribute('tabindex', '0');
playBtnEl.setAttribute('role', 'button');
// fake button needs keyboard help
playBtnEl.addEventListener('keydown', e => {
if( e.key === 'Enter' || e.key === ' ' ){
e.preventDefault();
this.activate();
}
});
}

// On hover (or tap), warm up the TCP connections we're (likely) about to use.
this.addEventListener('pointerover', LiteYTEmbed.warmConnections, {once: true});
this.addEventListener('focusin', LiteYTEmbed.warmConnections, {once: true});

// Once the user clicks, add the real iframe and drop our play button
// TODO: In the future we could be like amp-youtube and silently swap in the iframe during idle time
Expand Down

0 comments on commit 571be5d

Please sign in to comment.