paulirish / lite-youtube-embed

A faster youtube embed.
https://paulirish.github.io/lite-youtube-embed/
Other
5.6k stars 259 forks source link

Fix accessibility of progressive enhancement pattern #177

Open delucis opened 2 months ago

delucis commented 2 months ago

In #124 I naïvely “fixed” the issue of the play button being a link when following the progressive enhancement pattern by removing the href attribute.

However, this introduced an accessibility issue: <a> without an href attribute is considered non-interactive, and therefore can’t be tabbed to by keyboard users, preventing them from playing the video.

This PR seeks to fix this more correctly by replacing an <a> element entirely with a <button> when the custom element loads. This preserves interactive semantics.

To test I loaded the progressive enhancement example. Before this change, the play button is not focusable with the keyboard. After this change, the play button can be focused as expected.

jrouleau commented 2 months ago

The replaceWith will also remove the element's children. The default span will then be recreated in the following block, but as the user may have customised this, we should probably also move the children to the new button element