@@ -197,16 +197,41 @@ defineExpose({
197197player ,
198198})
199199
200+ // Keyboard accessibility: dispatch the configured trigger event on Enter/Space
201+ // so users navigating via keyboard can activate the placeholder (fixes #797).
202+ const keyboardTriggerable = computed (() => {
203+ if (isTriggered .value )
204+ return false
205+ const triggers = Array .isArray (props .trigger ) ? props .trigger : [props .trigger ]
206+ return triggers .some (t => typeof t === ' string' && ! [' immediate' , ' onNuxtReady' , ' visibility' , ' visible' ].includes (t ))
207+ })
208+
209+ function onPlaceholderKeydown(e : KeyboardEvent ) {
210+ if (e .key !== ' Enter' && e .key !== ' ' )
211+ return
212+ e .preventDefault ()
213+ if (! rootEl .value )
214+ return
215+ const triggers = (Array .isArray (props .trigger ) ? props .trigger : [props .trigger ]).filter (Boolean ) as string []
216+ for (const t of triggers ) {
217+ if ([' immediate' , ' onNuxtReady' , ' visibility' , ' visible' ].includes (t ))
218+ continue
219+ rootEl .value .dispatchEvent (new Event (t , { bubbles: false }))
220+ }
221+ }
222+
200223const rootAttrs = computed (() => {
224+ const interactive = keyboardTriggerable .value
201225return defu (props .rootAttrs , {
202226' aria-busy' : status .value === ' loading' ,
203227' aria-label' : status .value === ' awaitingLoad'
204- ? ' YouTube Player - Placeholder'
228+ ? ( interactive ? ' Play video ' : ' YouTube Player - Placeholder' )
205229: status .value === ' loading'
206230? ' YouTube Player - Loading'
207231: ' YouTube Player - Loaded' ,
208232' aria-live' : ' polite' ,
209- ' role' : ' application' ,
233+ ' role' : interactive ? ' button' : ' application' ,
234+ ' tabindex' : interactive ? 0 : undefined ,
210235' style' : {
211236 cursor: ' pointer' ,
212237 position: ' relative' ,
@@ -265,7 +290,7 @@ const placeholderAttrs = computed(() => {
265290 </script >
266291
267292<template >
268- <div ref =" rootEl" v-bind =" rootAttrs" >
293+ <div ref =" rootEl" v-bind =" rootAttrs" @keydown = " keyboardTriggerable ? onPlaceholderKeydown($event) : undefined " >
269294 <div ref =" youtubeEl" style =" width : 100% ; height : 100% ; position : absolute ; top : 0 ; left : 0 ;" />
270295 <slot v-if =" !ready" :placeholder =" placeholder" name =" placeholder" >
271296 <img v-bind =" placeholderAttrs" >
0 commit comments