Item 4 from here needs attention
https://www.drupal.org/project/drupal/issues/2904243#comment-12405231
+++ b/core/themes/umami/css/components/blocks/footer-promo/footer-promo.css
@@ -0,0 +1,47 @@
+.footer-promo__text a {
...
+.footer-promo__text a:after {
+++ b/core/themes/umami/css/components/navigation/tabs/tabs.css
@@ -0,0 +1,35 @@
+.tabs li {
...
+.tabs a {
...
+.tabs a.is-active {
...
+.tabs a:focus,
+.tabs a:hover {Please go through the CSS selectors using elements. We should try convert as many of them to classes as we can since it will make future changes easier for us.
Update to Issue Summary
This issue is to ensure that - as much as possible - we theme the Umami theme via BEM CSS classes and do not write CSS for specific HTML elements. This means we theme items such as links in tabs using a class like .tabs__link instead of .tabs a. This has the benefit of reducing CSS specificity, but also means that CSS does not leak out into other things. In this example, all a elements inside the .tabs class could be affected (e.g. potentially links in contextual links).
| Comment | File | Size | Author |
|---|---|---|---|
| #82 | interdiff.txt | 2.29 KB | lauriii |
| #82 | 2936875-82.patch | 12.26 KB | lauriii |
| #81 | Screenshot 2023-03-21 at 9.44.35 AM.png | 138.27 KB | smustgrave |
| #79 | interdiff-75-79.txt | 1.32 KB | markconroy |
| #79 | 2936875-79.patch | 12.64 KB | markconroy |
Issue fork drupal-2936875
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
markconroy commentedComment #4
hiway commented.linkclass name instead of a link selector in CSShook_preprocess_menu_local_task()on theme level to mark local task menu links with special classes "tabs__link"Comment #5
hiway commentedComment #6
thamasMark it RTBC as it works. Thanks @hiway!
I have some thoughts, however. (We may create followup issues.)
We have this already (following Classy):
.tabs .tab {A
.tab(anlielement) never will be found outside.tabs(aulelement) so it should be something like.tabs__item.From the patch:
.tabs .tab__link {One of the goals of styling (BEM) classes instead of HTML elements is lowering specificity. So we should write
.tab__linkonly (without.tabs). Unfortunately, if we do that it will be overridden by higher specificity styling coming from Classy.Also, it should be
.tabs__linkinstead of.tab__link(see above).Similar things about footer promo block. E.g. this does not follow our CSS coding standards about BEM:
.block-type-footer-promo-block .footer-promo-content .linkIdeally we would have something like
.footer-promo__linkonly.Comment #7
lauriiiCould we open a follow-up issue for the BEM adjustments as per #6?
We should not read render array keys directly because it might cause problems with cacheability. See #2660002: Allow explicit bubbling of cacheability metadata inside Twig template (when accessing data from instead of rendering render arrays) for more background information.
Comment #9
hiway commented@lauriii In the second part of your comment #7 you told:
Is it true for a field templates? Because I was debugging cache tags and they where the same when I was using
item.contentoritem.content['#url']in the link field template.If we should anyway do that for field templates, then regarding to the linked thread I can assume that I should use something like this in the link field template:
Am I right? Thank you.
Comment #10
lauriii@hiway did you set any additional cacheability metadata in
item.content? Core might not set any additional cacheability metadata there, but we cannot guarantee there isn't any custom code or contrib modules doing that.Is there any way we could just render the full render array? If we could do that, we wouldn't even have to think about workarounds.
Comment #11
hiway commented@lauriii Yes, you are right, we can try attach need classes in the field preprocess. I will create a new path soon. Thank you.
Comment #12
hiway commented@lauriii I got a new patch which includes all mentions from previous comments from @thamas - #6 and from you #7. Please review these solution.
Comment #13
hiway commentedComment #14
hiway commentedI changed this to "Needs Review" regarding to the changes in this comment #12
Comment #15
parijke commentedI've tested this one and it works. The a element selectors are nice replaced with bem-styled classes.
Comment #16
parijke commentedComment #17
lauriiiOverall this looks nice cleanup. It also seems like this already addresses #6 so we don't need to open a follow-up 👌
This is not used anywhere.
Comment #18
hiway commented@auriii Thanks for that notice. I leaved variable and just used it in the classes definition loop, where the string was before:
Think that's the good way.
Comment #19
hiway commentedChanging it to to the "Needs Review" after last patch
Comment #20
mcannon commentedI tested this in all D8 compatible browsers and the tabs and block links have been replaced by BEM classes and styles.
Comment #21
mcannon commentedComment #22
lauriiiWe can remove these lines of inline documentation since they don't bring any new information on top of what can be seen quite easily from the code.
Why are we adding this class? It is not being used anywhere.
Comment #23
hiway commented@lauriii Regarding to your question, about why are we using this class:
$variables['items'][$key]['content']['#options']['attributes']['class'][] = $bem_block_class;In current situation yes, this class is not used. But regarding to the BEM methodology principles the link itself can be a block and that class is the actual block name. In the real BEM projects any link is a block and usually the block name is "link", that's why I decided to keep that class there. But we can remove it if you really insist, so far we are using only naming conventions here.
Comment #24
hiway commented@lauriii I removed not need comments and kink block class name.
Comment #26
pawandubey commented@hiway
Please re-rolled the patch again so we can verify the same in 8.8.x version.
Comment #27
hiway commented@pawandubey Here is the new patch.
Comment #28
hiway commentedComment #29
paulsheldrake commentedPatch 27 works for me
Comment #31
yogeshmpawarAll looks good so setting back to RTBC! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).
Comment #32
pawandubey commentedRTBC+1 as the re-test also passed
Comment #33
lauriiiThere are still multiple instances where elements are used in selectors. The most concerning instance we should at least include in the scope is that we attach styles directly to
buttonelement in the base.css.Comment #34
hiway commented@lauriii The scope of this particular ticket was described in the description, and there's nothing about buttons and so on. So, may be better to create a big followup ticket which will cover all cases where we are using selectors in CSS rules? And as I understand, base.css file describes styles on the top level, saying, for global scope, so it may have selectors in rules to create default styles, may be not, but as far as this file is out of components, I think it's allowed to have selector rules there.
Comment #35
volkswagenchicktagging for DrupalNorth 2019
Comment #36
markconroy commentedTagging for drupaldevdays, which is on this week.
Comment #37
lauriii@hiway the original comment in the parent issue that requested to go through all selectors that are not using classes. I'm not too keen to a certain method of getting that done - if there's a significant amount of instances that need changes, it might be better to collaborate in multiple issues. However, often times working on multiple issues creates unnecessary overhead. What we are trying to achieve is to have as few selectors as possible using element type for applying rules. This is required to make us compatible with BEM and to make maintenance easier.
That is correct, but we want that file to be as small as possible. According to BEM, we are actually not supposed to have this kind of file at all because it makes maintenance harder. For example, button is a commonly used element that shouldn't have styles attached based on the element type.
Comment #38
hiway commented@lauriii, thanks for your answer. I see what you say, will try to manage our goals when will have a time to work on this issue.
Comment #39
volkswagenchickTagging for DrupalCamp Colorado 2019 (Sunday August 4)
Comment #40
hiway commented@lauriii, I have a chance to revise the base.css for a theme to clean up general selector rules. Instead of the form elements we also have there styles for typography: h1-h6, ol-ul, blockquote, img. And also there are styles for html, body and a selectors. What should we do with these styles? Leave it there?
Thank you
Comment #41
hiway commented@lauriii Regarding to your request about base.css, I refactored that file and deleted all form selectors from there and moved them to the appropriate form components CSS files, all element selectors there changed to class names.
So, guys, please take a look to the updated path.
Thank you.
Comment #42
hiway commentedComment #43
volkswagenchickTagging for badcamp2019, thanks! (October 2-5)
Comment #48
shaalComment #52
smustgrave commentedPatch or MR doesn't apply anymore
The last patch or MR doesn't apply to the target branch, please reroll the code so that it can be reviewed by the automated testbot.
Comment #53
markconroy commentedComment #54
markconroy commentedRe-rolled to work against 10.1.x
Comment #55
markconroy commentedBetter interdiff
Comment #56
markconroy commentedComment #57
markconroy commentedCoding standards fixes.
Comment #58
smustgrave commentedMoving to NW for the issue summary update requested in #37. If you could include what elements you are replacing with classes, would be very nice if it could use the default issue template.
Testing the actual code on umami install on D10. I checked the search bar for button class and that css is being used.
Could not find a textarea.
+1 for RTBC after the issue summary update.
Comment #59
markconroy commentedThanks @smustgrave.
Given that this issue is more than 5 years old, I can't give much more info than what is currently in the IS - basically, "let's try to theme Umami by BEM CSS classes and not theme it by targeting html elements themselves".
I'd really like to get this merged before we end up with the latest patch being way out of sync with the theme and taking a couple more hours to re-roll. If there's any follow-ups, we can look after them in a follow-up issue, but in the meantime there's been great work done in this issue by @hiway and others.
Issue Summary updated.
Comment #60
markconroy commentedComment #61
markconroy commentedComment #62
smustgrave commentedMaybe we get this one in and then open a follow up to re-evaluate if additional changes are needed?
Comment #63
lauriiiAgreed that it would be nice to land this BEM clean-up! Thank you for working on this @markconroy and @smustgrave! 🙏
I'm not sure this is doing anything because it looks like there's another rule with selector
.footer athat overrides this 🤔It looks like this is adding CSS files that do not exist 🤔
Comment #64
gauravvvv commentedAddressed #63, attached interdiff and patch for same. Please review
Comment #65
smustgrave commentedPoints have been addressed thanks!
Comment #66
lauriiiThis needs some more manual testing. There's at least one regression with the search input.
Before:


After:
Comment #67
markconroy commentedIt looks like the patch is removing all the styling for
inputbut not replacing it with other CSS (for .form-text, .form-email, etc). The specific class that we need to fix that regression is.form-search.Comment #69
kunal_sahu commentedI am working on this issue , will provide an patch soon. Thanks
Comment #70
markconroy commentedUnassigning.
Comment #71
markconroy commentedA further update to this patch:
.form-labelto all labels and uses this class to theme labels.form-textareaclass.form-textand.form-emailclasses.search-form .form-searchclassSide-by-side screenshots of the contact and search pages (the only pages regressed by the previous patch) attached.
Comment #72
markconroy commentedSorry, I forgot to upload the patch and interdiff ;-)
Comment #73
smustgrave commentedRemoving credit from #68 has nothing was added.
Reviewing the patch #72 on an Umami install and I'm getting the same screenshots as @markconroy so don't think anything broke.
Comment #74
markconroy commented@lauriii any chance we could get this committed? I want to create a follow-up issue to convert the theme to using css variables, but don't want to start any work on that until we have this in core.
Comment #75
lauriiiNice to see that this is shaping up! Few small comments that occurred when looking at the patch:
Couldn't these selectors be simplified just to
.footer-promo-block__link?We should add @file documentation here 😇
The block class is added in
core/profiles/demo_umami/themes/umami/templates/components/footer-promo-block/block--bundle--footer-promo-block.html.twigwhich means that for other bundles it's not guaranteed that the block class exists. Maybe we can just hard code this for the footer-promo-block use case?I think after we have made these changes, this is ready to be committed 😇
Comment #76
markconroy commentedThanks @lauriii
We need to leave the
.footer apart of the CSS in the footer promo block, or else our css gets overridden by.footer athat is in the footer CSS file.I've the other items fixed now.
Comment #77
smustgrave commentedThink this is good to be looked at again.
Comment #78
lauriii#76: If we'd want to get rid of those in the selector, we could duplicate the class selector. I.e.
.footer-promo-block__link.footer-promo-block__link. We've used this in Claro because it allows increasing the selector specificity without adding additional dependencies.Comment #79
markconroy commentedGood tip @lauriii. Thanks. Attached.
Comment #81
smustgrave commentedFailure in #79 seems unrelated
Installed a fresh Umami install with patch #79 and the footer seemed to still function
Comment #82
lauriii"Improved" how the class gets added to the link. I don't know if this is too much of an improvement but at least it's more consistent with other places where we do similar things, and it seems less prone to issues when the field config gets modified.
Comment #83
markconroy commentedLooks good to me, thanks @lauriii
Comment #85
lauriiiCommitted 161f201 and pushed to 10.1.x. Thanks!
Comment #86
markconroy commentedWoo hoo! Thanks.
Comment #87
quietone commentedFinal manual testing was done in #81, removing tag.