-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Custom editor styles on element selectors effect block control styles. #10178
Comments
I'm pretty sure
|
Reckon I should go ahead and do a PR on this? Maybe we cut it down to a reset of only the most commonly used properties of By adding the following to the top of
I've see zero side effects in my tests. |
This is indeed a good idea, but I don't like the fact that we need to polyfill it for IE11. Can we just start with the other browsers for now? I'm worried about the extra bytes in CSS this will create. That said, I'm wondering if you considered using the editor styles mechanism to provide your editor styles, it shouldn't interfere that much using this technique. https://wordpress.org/gutenberg/handbook/extensibility/theme-support/#editor-styles (The editor styles work better in 4.2 RC1) |
Supporting all browsers including IE11 wouldn't be a problem.
That being said, I forgot about the editor-styles mechanism.
This targets the block controls even more specifically. To the point where unsetting I'm going to think about it some more but right now I don't know how this initial proposal could work. To be clear, my whole point here is that I want my editor buttons and inputs to look as they do on the front-end. |
One possible solution here would be to modify the way the style wrapper #10956 works for non-"root" selectors. In addition to wrapping selectors, we add a An example of a modified user's editor-style would look something like this:
The |
@m-e-h I'm curious — how much of this could be solved by applying a generic reset in CSS to our components and making their selectors more specific, so our component styles are less likely to be impacted? I think I'd personally feel more comfortable with that, vs. a CSS rewriting hack which seems more fragile. |
Yes @chrisvanpatten a CSS reset like I originally proposed in this issue would work perfectly for those that are enqueuing their styles without using the However when using the current CSS rewriting hack, the themes styles become more specific than our reset: Perhaps it's worth throwing a reset at the top of the components anyway to cover those not using the |
An example
Since the controls on the blocks don't specify The following reset, placed before core defines any styles will ensure any properties not specified(by at least a single class selector) later in the stylesheet will retain their initial or inherited values.
Now we add the wrapper to our theme's
It overrides our reset and our button control. We can increase our reset specificity:
But now our reset is overriding our own control styles. |
#11505 is a duplicate report I made of the above issue: button styles in Twenty Seventeen's editor CSS, pulled into the editor with The culprit is the It makes more sense to move that discussion here, so closing #11505 in favour of this issue! |
Hey folks - I'm going to remove the documentation label on this, as I'm not entirely sure documentation is appropriate here. I was prepared to write this off as an edge case but if it's happening in the |
Tested and confirmed that using Steps to reproduce:
Result: buttons in the block toolbar and the empty/starter block are affected by the custom editor styles, but the expectation was to be able to use style elements such as
|
I really think this is or will become a bigger issue than it seems. When it comes to current themes, my guess is that many (most?) will simply All of these themes will be pushing their What kind of affect will that have on the UI? So how do we protect the core components? Both of these options would be made much simpler and more scalable if we can add a uniform
I'm happy to test some things and create a PR but tracking down each editor element to target is a tedious task. I want to first make sure this is worth spending time on. @youknowriad Do you think any of these options are worth exploring? |
I'm open to the idea that there's more we can do here, but it would be helpful to have more hard evidence that this will be a problem. It's definitely something we've seen happen but the reports have not been overwhelming. As far as I can tell the main problematic elements are I'm just keen to make sure we don't over-correct here — consider me a devil's advocate for the purpose of getting to the root of the problem :) |
I'm open to improvements here but I agree that it remains to be seen if it's a big issue or not. Most themes are handling this pretty well for the moment.
My concern here is that we're building something context agnostic, which means our components are not WP only, people can also add third-party components in the mix. So this won't scale properly.
I think this is probably the most promising way to solve it but I think we should add it case by case to the components we want to "protect". like |
Thanks for the responses! It could always just be a small issue where themes nudge the UI elements enough to make things feel a little unpolished but not broken. Maybe I'll start with the buttons and see if there's a simple side-effect free reset. |
I think it's important to have a long term view, and a near-term view. Long term, the utopian and possible not fully achievable goal should be that the front and backend look exactly the same and it should be trivial for the developer to make it happen, perhaps even just load the theme stylesheet itself into the editor. Near term, we should strive to make the backend look like the frontend, but I think we should also be okay with a few inconsistencies here and there. This is quite advanced stuff if you think about it, and even just setting a font and a background color goes a long way. Honestly in my opinion the Twenty themes, though perhaps especially TwentyNineteen go way farther than I expected possible or even necessary. I mean that's delightful, and it's a wonderful way of explaining the point of the whole thing in the first place. |
@MichaelArestad I'm sure this will introduce issues of its own (loss of semantic meaning being one of them!), but in this case, would it work to swap lists for something more generic like |
It could if we went heavy on aria attributes. This could be something to keep in mind. |
|
@benoitchantre Are you using the the If so, my guess would be the svg icons are inheriting your The svg icons have this:
If you have a
Which would override
And then yep, the That's just one possible scenario. I'm sure there are other ways it could happen. I'm sure there are plenty more cases like this where folks don't report it and just assume the UI is unpolished. I'm hoping to put together a PR soon that would better protect the core components from things like this. |
Heck yes. How so? |
@m-e-h Thank you for your detailed answer. Yes, I’m using For information, this is in the context of WP rig v2.0 I have set some overrides to limit the consequences, but not every case is covered and a solution at the editor level would be better.
|
@MichaelArestad I've had a couple ideas that should work, ..in theory 😕 🤔 The trick is getting around the
Most of the component classes are single class selectors so currently they're a 10 in specificity. Something like this: reset
component
user style
With specificity this precise the order won't matter but ideally, I guess, the reset should come first. Anything look off with this? Anyone? |
@benoitchantre it may or may not be helpful in your situation but I created a postcss plugin to get me by until core gets a fix for the element style leakage. https://github.com/m-e-h/postcss-editor-styles |
This is a really interesting idea, @m-e-h. Basically, provide a very strong reset, then raise the specificity on every subsequent editor style. Is that a correct interpretation? If yes, what are our current blockers to implementing that with the current Windows 7 is going out of support soon, and while I believe IE11 will still ship with Windows 10 for a while, there's an argument to be made that the new Chromium based Edge counts as a new version. Given a historical "support the last two browser versions", we COULD be looking at supporting Chromium Edge and Edge in the not too distant future, especially if there are solid arguments to doing so. (Note that I say that in the most unofficial capacity possible, this is mostly wishful thinking :).) |
More or less.
The current editor style rewrite only deals with theme styles. This doesn't touch theme styles.
No magic. It uses
Can't think of any "limitations" really. I wasn't around much when the rewrite thing was introduced so I don't know all the problems it was meant to solve. It does a good job of keeping theme CSS out of the admin sidebars (and throwing off the cascade 😉 ). I realize we have a lot of excellent JS devs in here and it's a good thing we do!
Isn't there always? |
This sounds good to me. I'm not necessarily opposed to a theming system that goes outside the editing canvas (though I'm struggling to understand the use cases?), but yes I'm definitely looking at making it easier to make editor styles.
The rewriting engine intends to solve these problems:
Screenshot of 3 in action: |
@jasmussen Thanks, as always for the thorough answer! That all makes sense
I'm not talking about doing anything that we're not already doing. Many of the UI components, that this is meant to protect, aren't limited to the editing canvas. I suppose for the purpose of this experiment we can start out assuming that everyone is using the Testing with just this:
and I've bumped up the specificity evenly across 'block-editor', 'editor', 'components', and 'edit-post' stylesheets using postcss during the build process. Changing the default themes to twentyseventeen twentyseventeen I'll put my rough first pass together in a PR for some feedback and testing. I'd never even looked at Gutenberg's build process till last night so I'm definitely going to need some direction on any conventions used there. |
That's very cool!
Please if there's ever any blockage here, you know where to find me. You can ask openly for help in the core slack, #core-editor, or you can ping me directly (@joen in core slack), or just here. Happy to help, so we can get your expert input! |
Thanks @jasmussen ! PR created here #15377 It's still an early draft. I know I need to move some of the files around but it seems to work well. |
I've encountered similar issues with the components buttons as well as the permalink. As noticed before, it's problematic that Gutenberg's styles for editor controls are not wrapped in I like some of the suggestions made here, including the PR by @m-e-h, which seems hard to get right though. I know it's not so great from a pure CSS standpoint, but could we not wrap Gutenberg's styles in the |
My plate is all kinds of full, but this is still on my radar. I hope to resurrect the ongoing efforts here that were close, if I recall correctly. |
I'd really like to explore some options here and hope I can find some time in the near future to do so. My extra time unfortunately disappeared around the time I started experimenting with solutions for this. An For example, I don't think a wrapper would help at all with the case used at the start of this issue thread. #10178 (comment)
|
Taking a look at this with slightly fresher eyes, it seems clear that while theme developers can work within the limitations currently present due to the CSS bleed, it's still onerous and they shouldn't have to. So while it may not be urgent to address this issue, addressing this issue should make virtually all developers lives easier. In my experience, it's always useful to look at the utopian solution first, and then plot a course towards that. In my estimation, Shadow DOM was created for this exact purpose; to encapsulate an element from inheriting styles. It seems like if we were able to encapsulate the most in-editor used components, such as the Block Toolbar, the Placeholder, and the Mover control, we'd be mostly there. I know Shadow DOM has been explored and abandoned, but I can't recall what was holding us back — was it the lack of support in IE11/Classic Edge? Given the new Chromium based Edge supports Shadow DOM, could we consider editor styles to be a progressive enhancement for modern browsers? Similar to how Shadow DOM protects the styles of an element, the most promising approach from this thread seemed to involve strengthening the UI styles to insulate them from being overridden by editor styles. The main point of feedback against this approach, cc @youknowriad, was that ideally we should be be content agnostic: since we can't know what additional components a plugin developer might add to the UI, it seems confusing to just protect a few elements. But would this not also be the case with Shadow DOM? And is there a way to simplify the API surface so that controls you do not want to inherit theme styles can be wrapped? I believe this is what @m-e-h is referring to here. So it seems like defining what content agnosticism we want is key to unsticking this issue. Let's explore that a bit:
Based on the above two take-aways, it seems like a pragmatic appraoch would be to:
Potentially this would solve 80% of our problems. And it might even plot us a path towards Shadow DOM. Long term, Shadow DOM would protect elements, but near term, higher element specificity would do so. Specifically this idea seems like it could be compatible with an allowlist of elements to protect:
To throw it out there, this could be an In the end this would provide developers with a set of components they know won't inherit CSS from theme styles, and instructions for how to protect their own elements in a similar way. Would love your thoughts, and would love to unstick this. |
Can we get an update from someone on this very old issue? |
The current PR that seems to work in this issue is #33494 |
Unless I'm missing something, the introduction of the iframe for the editor content should be preventing the most common of these issues. |
Describe the bug
If in my theme-editor-styles.css I have the following:
then havoc is wreaked on my editor.
Expected behavior
The styles above are exaggerated but I don't think styles on
button
orinput
elements are totally edge cases. #10067 (comment)Possible solution
One fix that would need more testing is to
unset
styles on the Gutenberg specific class before styles are added.So, for example, adding the following to the top of
components/style.css
fixed thebutton
styles for me:This could be done for each class that Gutenberg applies to an html element other than
div
. Mostlybutton
andinput
I would guess.Desktop (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: