-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Unable to add CSS class names to editor iframe #56831
Comments
See #17854 and gutenberg/packages/block-editor/src/components/iframe/index.js Lines 144 to 152 in cad8fae
The solution is to use the |
Reopening as there should be a more logical way to do this. |
I'm just throwing this out there without much thought, so it might be irrelevant or useless. The comment above says:
I wonder if it'd be okay to inject the return value of body_class() in |
Here's a proposal PR. I'd appreciate any feedback #68538 |
@Mamaduka has suggested that we should not use $settings and Once the property is part of the 'core/block-editor' state, it becomes pretty easy to hook in and keep the body classes up to date. |
Thanks, @colinduwe! I must look up why iframe limits classes copied from the parent body. The original code was introduced in #32057, but I don't see any related comments. My current guess is to avoid leaking styles into the iframe. Technically speaking, I don't see a difference between injecting values returned by Code in question: gutenberg/packages/block-editor/src/components/iframe/index.js Lines 144 to 152 in cad8fae
|
@Mamaduka The current iframe body class implementation isn't flexible enough. It currently only runs onLoad and the classes are proscribed there in the onLoad. Instead, the bodyClasses should be a part of the blockEditorStore. Have a look here. Currently, body classes that we had in the TinyMCE era are not present in the ownerDocument.body.classlist. For example, page-template. I'd also like to call attention to #17854 begun in 2019. Is there a single issue where we should be discussing this? |
Agreed that this should be subscribable. The point of the origins requirement is that the frame colour can be changed at any time when clicking on a page-level colour selector. |
Yes, it would be nice to consolidate this into a single issue. The usual policy is to use the oldest issue, reference new ones and close them. Somewhat related: #60299 (comment). |
Description
I'm attempting to add CSS class names to the new iframe in the editor using JavaScript. The aim is to apply a user-selected accent colour in the editor.
I've only been able to do so using an overly-complicated combination of MutationObserver (to detect when the iframe becomes available) and a setInterval to repeatedly try to apply the class name until it sticks. This seems to be unnecessarily complex. Is there a better solution?
I've tried to add the class names using the
admin_body_class
hook in PHP, but this doesn't feel right (as it's PHP) and it also only appears to work on the mainbody
(which doesn't help, as it's hidden by the iframe).Step-by-step reproduction instructions
See the code example.
Screenshots, screen recording, code snippet
https://gist.github.com/markhowellsmead/01c8c29937162e93a11e21c8209872d1
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: