Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the CSS class is-dark-theme is added to the editor iframe body #60300

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ function Iframe( {
function onLoad() {
const { contentDocument, ownerDocument } = node;
const { documentElement } = contentDocument;
// Get any CSS classes the iframe document body may initially have
// to re-apply them later together with the ones of the main document
// body. This is necessary for some CSS classes for example the
// `is-dark-theme` class added by useDarkThemeBodyClassName.
const initialIframeBodyClasses = Array.from(
contentDocument.body.classList
);
iFrameDocument = contentDocument;

documentElement.classList.add( 'block-editor-iframe__html' );
Expand All @@ -151,12 +158,15 @@ function Iframe( {
// be added in the editor too, which we'll somehow have to get from
// the server in the future (which will run the PHP filters).
setBodyClasses(
Array.from( ownerDocument.body.classList ).filter(
( name ) =>
name.startsWith( 'admin-color-' ) ||
name.startsWith( 'post-type-' ) ||
name === 'wp-embed-responsive'
)
Array.from( ownerDocument.body.classList )
.concat( initialIframeBodyClasses )
.filter(
( name ) =>
name.startsWith( 'admin-color-' ) ||
name.startsWith( 'post-type-' ) ||
name === 'wp-embed-responsive' ||
name === 'is-dark-theme'
)
);

contentDocument.dir = ownerDocument.dir;
Expand Down
Loading