-
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
Fix/button css specificity #12005
Fix/button css specificity #12005
Conversation
If the duplicate selectors for the color names are acceptable, I'd also like to apply the same to the font sizes (in a separate PR) so we can partially close #11200. |
Thanks so much for this pull request. Really appreciate it 👏 It's a little bit hard to follow the CSS changes — they seem good on the face of it, but I'd appreciate a sanity check and good testing across at least the vanilla style and twentynineteen, plus all variations. Here's TwentyNineteen: Here's the vanilla style: As you can see from the above, all looks good except for the twentynineteen variation preview. However an initial 👍 👍 to this, and thanks for the PR. @chrisvanpatten what are your thoughts on these changes? The double-specificity hack is super clever, but is it too clever? Do we need a CSS comment to explain what is going on? Are we actually making it easier for themers, or are we just pushing the complexity elsewhere? How sure are we that the |
As a followup, I fixed the double outline issue in #12051. |
Thanks for checking this out @jasmussen! Twenty Nineteen isn't great for testing this since it's not using the default color methods and options. Also, while not specifically to blame for the results in your Button Preview screenshot, it's worth noting the influence that the mapped Not sure I'd call the "duplicate selector for the purpose of specificity" a hack. It does behave the way it's supposed to according to the W3C https://www.w3.org/TR/selectors-3/#specificity
Though we probably could use a CSS comment here since this rule may be new to some. I'm not aware of any performance issues with the |
As for @chrisvanpatten's suggestion to use repeated classes for font sizes, I'd absolutely recommend that. Might also be worth pulling these style from the |
YESSSS this would be amazing. Having these classes separated out would be so cool.
I think this is more straightforward, and easier to parse, vs I think this is a sensible path forward. I don't think it's necessarily the best scenario (that would be Gutenberg generating CSS for color palettes and font sizes so we can ensure correct specificity) but this is definitely a step in the right direction. I think anything we can do to simplify the CSS and reduce specificity to the bare minimum will make things easier for themers to override. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work as intended, and have a lot of thought put into it, plus sanity checks. I trust that it improves the situation, so let's keep moving. But do add a comment about the double-use of the selector as a CSS comment, something a la // Double the class name to increase specificity
... something in that vein. Thanks!
I put it in the 4.5 milestone, which is the release candidate milestone. This is a big one. If you feel unsure about an aspect, let me know and we can move it. |
On a glance, this wasn't obvious to me at all. Is it not also making a very fragile assumption about the specificity of the thing it is meant to override? Could it be enough to do |
This is actually a common use of |
I don't disagree @aduth. I think the case could be made for It is making an assumption that what it's overriding will precede it and have no more than two classes or a class and a pseudo-class such as
|
Yes, but it makes an assumption that the hypothetical future maintainer is aware of these circumstances should they decide naively to add some specificity to the class selectors these are meant to override. |
That's a possibility. Would be awesome though if WP could right it's past transgressions and make single class selectors it's norm or even the rule. I'm going to continue to help however I can to move us in that direction. I'm not against |
Can we at least add the explaining comment? #12005 (review) Otherwise, I'm fine to have this land as-is as an improvement over the current state. |
Added the comment per @aduth's suggestion. Let's continue iterating on this kind of improvements. |
test/e2e/specs/links.test.js failed on line 302 on PHP latest. Restarting it. |
All tests are passing - @aduth or @youknowriad do you want to merge this? |
Description
Reduces specificity in core button styles to ease clashes with theme styles.
This has been explained in further detail here #11779 (comment)
This takes care of some cases mentioned here #11677
And attempts to solve #11998 by giving the Twenty-* themes 1 single button class selector to style
.wp-block-button__link
.It also strengthens the specificity of the color and background-color classes so they'll override when the user chooses them.
The button color was added to the parent
.wp-block-button
element so that the link couldinherit
the color whether it be a default button with$white
text or an outline button with$dark-gray-700
text.This drys up the code some and allows for single class selector overrides.
The CSS selectors for the Text Color and Background Color settings have been given more specificity to override
.wp-block-button__link
even with the pseudo-classes.wp-block-button__link:hover
.Duplication of the class selector is used here for two reasons:
How has this been tested?
In depth visual tests were done in browser.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: