-
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
.has-vivid-cyan-blue-background-color.has-vivid-cyan-blue-background-color #12986
Comments
Class names are doubled to increase specificity to assure colors take effect over another base class color. See https://github.com/WordPress/gutenberg/blob/cddee64697706f6b797a9fba39d075eff95ee0b0/packages/block-library/src/style.scss and discussion at #12005. Certainly looks odd though. |
Ok, I understand but in such case the problem is that https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/ says that
so this instruction is wrong? |
That's a good question, do we still need the duplicate now that we did some work on the CSS specificity? cc @jasmussen @kjellr Should we update the docs? |
From a quick attempt, we don't: #15104. I would very much like a sanity check on that one — it appears to be working as intended in my tests, and from looking at the CSS, the reduced specificity of the button block selector should mean it works as intended. But I would very much like testing regardless, in case I'm missing something obvious. If it works as I hope it does, I'm very happy that the big PR I struggled with is yielding benefits now! |
The docs seem correct to me. I'm not sure what theme-created classes have to do with the specificity of the core color classes.
Pretty sure we do. see #15104 (comment) I'm thinking this has more to do with the confusion that duplicate classes might cause? If so, there are other ways to add specificity. The duplicate classes seemed like the best option to me. Single class/* specificity = 10 */
.has-luminous-vivid-amber-color {
color: #fcb900;
}
Duplicate class/* specificity = 20 */
.has-luminous-vivid-amber-color.has-luminous-vivid-amber-color {
color: #fcb900;
}
:root qualifier/* specificity = 20 */
:root .has-luminous-vivid-amber-color {
color: #fcb900;
} This is my method of choice for personal projects.
:not() qualifier/* specificity = 20 */
:not(.anythingWorks) .has-luminous-vivid-amber-color {
color: #fcb900;
}
Parent class qualifier/* specificity = 20 */
.wp-block-button .has-luminous-vivid-amber-color,
.wp-block-pullquote .has-luminous-vivid-amber-color {
color: #fcb900;
}
Element qualifier/* specificity = 11 */
a.has-luminous-vivid-amber-color,
blockquote.has-luminous-vivid-amber-color {
color: #fcb900;
}
!important.has-luminous-vivid-amber-color {
color: #fcb900 !important;
}
|
I see now what you mean by "updating the docs". I guess they should be updated since copying and pasting what's there now wouldn't work for links. Pretty sure link pseudo-classes are the only area giving us an issue. So we could always just add those specific pseudo-classes. So something like this maybe:
I personally like a higher specificity on every utility class but I also understand keeping things familiar for the average developer. This may be a good compromise. What do you think @jasmussen? Wanna try this in #15104 or are we fine with the duplicate classes? |
It seems like the problem might be themes that wish to use the core color names, but override the rendered colors. Not saying that's a good thing — but it seems to be the edge case being solved for. |
Yeah, just now noticed that the example code in the docs didn't match up with the actual code. I could see that causing an issue for some every now and then. Btw, where you been @chrisvanpatten ?! 😄 |
I'm generally fine with whatever solves the problem at hand. Though I do think that the following might be much easier to parse:
and I can totally take a stab at that, including updating the docs to match (in a new PR), but before I go about that, is there consensus that this will work for us? You sure And yes, I think
For better or worse, that some day might be sooner than you think! |
Just wanted to second this. Since the doubling up of classnames is somewhat rarely seen, I'd support either a re-write along these lines, or just some more explanatory code comments above. |
I got a new job! Still lurking (and reading most tickets) but haven't had as much time to actively contribute. Hoping we start onboarding our platform to Gutenberg later this year so I can get back into it :)
I really like this solution. It's much more explicit, which is nice! |
Pretty sure.. I mean, it'll definitely count towards the hover style. And it should be the same specificity as what we have now, 20. But I'm wondering, what happens when a theme does something like .entry a { /* specificity: 11 */ }
.entry a:hover { /* specificity: 21 */ } Maybe something like this would be safer: .has-luminous-vivid-amber-color,
a.has-luminous-vivid-amber-color:link,
a.has-luminous-vivid-amber-color:visited {
color: #fcb900;
} That would match the 21 specificity. |
This fixes #12986 and is based on the conversation there. Instead of doubling the selectors to increase specificity, we are supplying the element as well.
So, I took a stab at this just now, and created a draft pull request: #15167. It seems to work as intended so far: The reason it's a draft is that I realized that the syntax discussed is very biased towards foreground colors, but doesn't take into account background colors. So the question becomes: do we still need high specificity for the background colors, or is it okay for those to have lower specificity? One thing we could do to increase the specificity of the background color, while still avoiding the duplicate selector, would be to do the following:
Curious what your thoughts are. |
These are single function, utility type classes so I don't think more specificity is going to hurt anything. I think we focused on links color because a lot of times Is |
|
Yep indeed those two screenshots look like one continuous one! But yes, I've remembered it 💪
Excellent question. Testing now:
So you see where this is going. Which brings us to an existential question around #15167: is it actually in improvement overall? It looks like if we mean to have additional specificity on at least the background colors, we either have to write a long explicit selector such as this:
... and we'll likely need to maintain that as well, as additional blocks add colors in a haphazard way ... OR, we can accept the duplicate classnames:
At this point, I'm back to where it feels like if we DO actually need to increase the specificity of those background colors, the duplicate classes even if they look wrong, is still the right way to go. And if that's the case, then we might as well use that same pattern even for the text colors too, then at least it's consistent. Any final thoughts before I close that PR and create a new one that just augments the code comment instead? |
I agree. But it is very "typo" looking.
It definitely looks more deliberate. And now that I see we've begun accounting for Like I mentioned previously |
I most definitly think :root reads less like a typo. It may be more advanced CSS, but advanced CSS is google-able, whereas the duplicated class definitely looks like a mistake. Tried it here: 9132137 — I personally like this a lot, and it's working for me: |
* Try tweaking the specificity of the custom color syntax This fixes #12986 and is based on the conversation there. Instead of doubling the selectors to increase specificity, we are supplying the element as well. * Try :root * Address feedback.
The selector is duplicated in /wp-includes/css/dist/block-library/style.css. It should not be.
The text was updated successfully, but these errors were encountered: