Skip to content

Classic theme site preview: Some elements may remain interactive #70050

@t-hamano

Description

@t-hamano

What problem does this address?

When the classic theme site preview is displayed, all elements inside an iframe are expected to be non-interactive via the following code:

onLoad={ ( event ) => {
// Make interactive elements unclickable.
const document = event.target.contentDocument;
const focusableElements = focus.focusable.find( document );
focusableElements.forEach( ( element ) => {
element.style.pointerEvents = 'none';
element.tabIndex = -1;
element.setAttribute( 'aria-hidden', 'true' );
} );
} }

However, I found that this code isn't enough to make all interactive elements non-clickable or non-focusable. The scenarios I was able to find are:

⚒️ Summary element

For example, you can expand or collapse the Details block content by clicking the summary element. The reason is that the summary element is not defined here as a focusable element.

Image

Elements that are not visible on initial load

For example, Twenty Twenty-One has a mobile menu toggle button. This element isn't initially displayed, but if you narrow down the iframe width, the button is displayed, which is interactive.

I think we'll probably need to use a MutationObserver to monitor changes to the DOM tree and make newly added elements non-interactive.

Image

Elements with event handler

Consumers may add event handlers to non-interactive elements. In this case, focus.focusable.find() can't detect the element.

<div class="wp-block" onclick="window.alert('clicked!')">Click Me</div>

Elements with the Interactivity API

Some elements may have the directives in their markup to add specific behavior the the DOM elements of the block. For example, the image lightbox.

Image

What is your proposed solution?

We need to find an ideal approach to correctly disable all interactive elements. Additionally, there may be other cases to deal with besides the ones I have mentioned.

Not that the approach to add the inert attribute to the iframe body may cause an accessibility issue. See #69522 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Style Book[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    Status

    🦵 Punted to 6.9

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions