-
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
Block styles affect the message inside the Warning component #40536
Comments
We now have two alternative PRs to fix this issue:
I just had another idea (and will likely add a third PR to the mix): Both this issue and #40826 originate from the fact that the Warning is displayed "inside" of the block. But there’s precedent for Warnings that are displayed outside (such as Invalid Block markup), and they don’t suffer from those issues. So I'd like to try that; I think there's hook for that. |
I've investigated a little bit and here's the summary of my findings (this is in addition to what Bernie mentions above)
|
I re-read Using Shadow DOM and, AFAIU, using a shadow tree doesn't prevent global styles from being applied inside in any way. What it does is the opposite. CSS styles defined inside the shadow tree are encapsulated there and ignored outside. That's certainly handy, but not in this case. 😅 I guess the best approach is using |
It's true that it doesn't prevent inheritance, but it prevents targeting its elements from the outside, though. Look at how this p {
color: blue;
} https://codepen.io/luisherranz/pen/OJQNVVG I didn't know |
Thanks for your example, @luisherranz; pretty useful. 💯 I have to say that I don't know how styles are inherited yet, TBH. It looks like some rules are inherited, some others not? If you, for example, add |
Good catch, thanks @michalczaplinski! This could be considered a more generic issue (it might affect existing GB warnings, such as the "Invalid block content" one), but I agree that it kind of gets in the way of #40898 being an exhaustive fix that we can merge in the short term 😬 Edit: Yep, looks like it affects existing warnings. This is a Group with letter-case set to all-uppercase, containing one unsupported block: |
Exactly. Some rules are inherited and others not. As you pointed out, the Shadow DOM prevents the styles inside of it from leaking out, but the inherited styles still affect the content inside of the Shadow DOM.
That's also true! If we only use |
I have dug a little deeper still and updated #40868 with the approach of using just There are some caveats that I have documented there. |
That's also true, although not what I had in mind when I made that comment 😄 There are a lot of tiny details with these APIs, so I've made a video to explain what I meant. But I think the current solution is great as it is, @michalczaplinski! EDIT: Now that I read your comment again, I'm not sure anymore if what you meant was what I meant already, or what you meant was that the shadow root can also be styled from the outside and conflict with the |
yes, I'm sorry, I think I typed out my previous response too quickly! 😅 What I meant is what you mentioned in the video! That when you use the light DOM, it can still be styled from the outside, even if you add the /* Don't think anyone's gonna write something like that outside of the Warning component */
.block-editor-warning__message {
text-transform: uppercase;
}
/* And if you add styles like that in your site, you probably have a bigger
problem or you know what you're doing :) */
p {
text-transform: uppercase;
} |
Description
I expect that UI warning messages (created using the
<Warning>
component) are not affected by the block styles (Block Supports and Global Styles).Step-by-step reproduction instructions
<!-- wp:post-comments /-->
Screenshots, screen recording, code snippet
Screen.Capture.on.2022-04-22.at.10-10-52.mov
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: