@@ -237,6 +237,7 @@ function Iframe( {
237
237
return (
238
238
< >
239
239
{ tabIndex >= 0 && before }
240
+ { /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
240
241
< iframe
241
242
{ ...props }
242
243
style = { {
@@ -264,6 +265,25 @@ function Iframe( {
264
265
// content.
265
266
src = { src }
266
267
title = { __ ( 'Editor canvas' ) }
268
+ onKeyDown = { ( event ) => {
269
+ // If the event originates from inside the iframe, it means
270
+ // it bubbled through the portal, but only with React
271
+ // events. We need to to bubble native events as well,
272
+ // though by doing so we also trigger another React event,
273
+ // so we need to stop the propagation of this event to avoid
274
+ // duplication.
275
+ if (
276
+ event . currentTarget . ownerDocument !==
277
+ event . target . ownerDocument
278
+ ) {
279
+ event . stopPropagation ( ) ;
280
+ bubbleEvent (
281
+ event ,
282
+ window . KeyboardEvent ,
283
+ event . currentTarget
284
+ ) ;
285
+ }
286
+ } }
267
287
>
268
288
{ iframeDocument &&
269
289
createPortal (
@@ -277,18 +297,6 @@ function Iframe( {
277
297
'editor-styles-wrapper' ,
278
298
...bodyClasses
279
299
) }
280
- onKeyDown = { ( event ) => {
281
- // This stopPropagation call ensures React doesn't create a syncthetic event to bubble this event
282
- // which would result in two React events being bubbled throught the iframe.
283
- event . stopPropagation ( ) ;
284
- const { defaultView } = iframeDocument ;
285
- const { frameElement } = defaultView ;
286
- bubbleEvent (
287
- event ,
288
- window . KeyboardEvent ,
289
- frameElement
290
- ) ;
291
- } }
292
300
>
293
301
{ contentResizeListener }
294
302
< StyleProvider document = { iframeDocument } >
0 commit comments