Play button bug when using progressive enhancement pattern
delucis opened this issue · comments
The documented progressive enhancement pattern adds a link inside the custom element to allow users to click through to the YouTube video even without JavaScript.
I’m seeing a bug where after the JS loads, the play button continues to link to YouTube, so clicking it navigates away from the page. (Clicking anywhere else on the poster image works as expected.)
In a couple of experiments I could fix this either by
-
Removing the
href
from the play button in theconnectedCallback
:playBtnEl.removeAttribute('href');
-
Calling
preventDefault
in the click handler:this.addEventListener('click', (e) => { e.preventDefault(); this.addIframe(); });
PR #124 implements the first of these approaches.