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).

Issue fork drupal-2936875

Command icon 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

markconroy created an issue. See original summary.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markconroy’s picture

Component: profile.module » Umami demo
hiway’s picture

StatusFileSize
new5.88 KB
  1. I have created a theme template override for a link field, and any link generated by link filed will no have a class "link", it give us possibility to use .link class name instead of a link selector in CSS
  2. I have implemented a hook_preprocess_menu_local_task() on theme level to mark local task menu links with special classes "tabs__link"
  3. Updated appropriate CSS files
hiway’s picture

Status: Active » Needs review
thamas’s picture

Status: Needs review » Reviewed & tested by the community

Mark 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 (an li element) never will be found outside .tabs (a ul element) 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__link only (without .tabs). Unfortunately, if we do that it will be overridden by higher specificity styling coming from Classy.
Also, it should be .tabs__link instead 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 .link
Ideally we would have something like .footer-promo__link only.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs followup
  1. +++ b/core/profiles/demo_umami/themes/umami/css/components/navigation/tabs/tabs.css
    @@ -19,17 +19,17 @@
    +.tabs .tab__link {
    ...
    +.tabs .tab__link.is-active {
    ...
    +.tabs .tab__link:focus,
    +.tabs .tab__link:hover {
    

    Could we open a follow-up issue for the BEM adjustments as per #6?

  2. +++ b/core/profiles/demo_umami/themes/umami/templates/field/field--link.html.twig
    @@ -0,0 +1,86 @@
    +          <a href="{{item.content['#url']}}" class="link">{{ item.content['#title'] }}</a>
    ...
    +        <a href="{{item.content['#url']}}" class="link">{{ item.content['#title'] }}</a>
    ...
    +        <a href="{{item.content['#url']}}" class="link">{{ item.content['#title'] }}</a>
    

    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.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hiway’s picture

@lauriii In the second part of your comment #7 you told:

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.

Is it true for a field templates? Because I was debugging cache tags and they where the same when I was using item.content or item.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:

…
{% for item in items %}
      <div{{ attributes.addClass(classes, 'field__item') }}>
        {% set cache_cath = item.content|render %}
        <a href="{{item.content['#url']}}" class="link">{{ item.content['#title'] }}</a>
      </div>
{% endfor %}
…

Am I right? Thank you.

lauriii’s picture

@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.

hiway’s picture

@lauriii Yes, you are right, we can try attach need classes in the field preprocess. I will create a new path soon. Thank you.

hiway’s picture

StatusFileSize
new4.69 KB

@lauriii I got a new patch which includes all mentions from previous comments from @thamas - #6 and from you #7. Please review these solution.

hiway’s picture

Status: Needs work » Needs review
hiway’s picture

I changed this to "Needs Review" regarding to the changes in this comment #12

parijke’s picture

I've tested this one and it works. The a element selectors are nice replaced with bem-styled classes.

parijke’s picture

Status: Needs review » Reviewed & tested by the community
lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs followup

Overall this looks nice cleanup. It also seems like this already addresses #6 so we don't need to open a follow-up 👌

+++ b/core/profiles/demo_umami/themes/umami/umami.theme
@@ -38,6 +38,20 @@ function umami_preprocess_field(&$variables, $hook) {
+      $bem_block_class= 'link';

This is not used anywhere.

hiway’s picture

StatusFileSize
new4.7 KB

@auriii Thanks for that notice. I leaved variable and just used it in the classes definition loop, where the string was before:

// Iterate through the items if field is multiple,
// and attach classes.
foreach ($variables['items'] as $key => $item) {
  $variables['items'][$key]['content']['#options']['attributes']['class'][] = $bem_block_class;
  $variables['items'][$key]['content']['#options']['attributes']['class'][] = $bem_element_class;
}

Think that's the good way.

hiway’s picture

Status: Needs work » Needs review

Changing it to to the "Needs Review" after last patch

mcannon’s picture

I tested this in all D8 compatible browsers and the tabs and block links have been replaced by BEM classes and styles.

mcannon’s picture

Status: Needs review » Reviewed & tested by the community
lauriii’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/profiles/demo_umami/themes/umami/umami.theme
    @@ -38,6 +38,20 @@ function umami_preprocess_field(&$variables, $hook) {
    +      // Prepare var to keep parent block name.
    ...
    +      // Define BEM block class name.
    ...
    +      // Define BEM element class name.
    ...
    +      // Iterate through the items if field is multiple,
    +      // and attach classes.
    

    We 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.

  2. +++ b/core/profiles/demo_umami/themes/umami/umami.theme
    @@ -38,6 +38,20 @@ function umami_preprocess_field(&$variables, $hook) {
    +      $bem_block_class= 'link';
    ...
    +        $variables['items'][$key]['content']['#options']['attributes']['class'][] = $bem_block_class;
    

    Why are we adding this class? It is not being used anywhere.

hiway’s picture

@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.

hiway’s picture

Status: Needs work » Needs review
StatusFileSize
new4.36 KB

@lauriii I removed not need comments and kink block class name.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pawandubey’s picture

Status: Needs review » Needs work

@hiway

Please re-rolled the patch again so we can verify the same in 8.8.x version.

hiway’s picture

StatusFileSize
new4.39 KB

@pawandubey Here is the new patch.

hiway’s picture

Status: Needs work » Needs review
paulsheldrake’s picture

Status: Needs review » Reviewed & tested by the community

Patch 27 works for me

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 2936875-27.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Reviewed & tested by the community

All looks good so setting back to RTBC! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).

pawandubey’s picture

RTBC+1 as the re-test also passed

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

There 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 button element in the base.css.

hiway’s picture

@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.

volkswagenchick’s picture

Issue tags: +drupalnorth2019

tagging for DrupalNorth 2019

markconroy’s picture

Issue tags: +drupaldevdays

Tagging for drupaldevdays, which is on this week.

lauriii’s picture

@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.

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.

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.

hiway’s picture

@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.

volkswagenchick’s picture

Issue tags: +dcco2019

Tagging for DrupalCamp Colorado 2019 (Sunday August 4)

hiway’s picture

@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

hiway’s picture

StatusFileSize
new12.05 KB

@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.

hiway’s picture

Status: Needs work » Needs review
volkswagenchick’s picture

Issue tags: +badcamp2019

Tagging for badcamp2019, thanks! (October 2-5)

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

shaal’s picture

Assigned: Unassigned » markconroy

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

Patch 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.

markconroy’s picture

Assigned: markconroy » Unassigned
markconroy’s picture

Status: Needs work » Needs review
StatusFileSize
new12.33 KB
new4.96 KB

Re-rolled to work against 10.1.x

markconroy’s picture

StatusFileSize
new4.96 KB

Better interdiff

markconroy’s picture

markconroy’s picture

StatusFileSize
new9.24 KB
new5.75 KB

Coding standards fixes.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Moving 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.

markconroy’s picture

Thanks @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.

markconroy’s picture

markconroy’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Maybe we get this one in and then open a follow up to re-evaluate if additional changes are needed?

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Agreed that it would be nice to land this BEM clean-up! Thank you for working on this @markconroy and @smustgrave! 🙏

  1. +++ b/core/profiles/demo_umami/themes/umami/css/components/blocks/footer-promo/footer-promo.css
    @@ -16,6 +16,27 @@
    +.footer-promo-block__link {
    +  color: #fff;
    +  background-color: inherit;
    +  font-weight: 700;
    +}
    

    I'm not sure this is doing anything because it looks like there's another rule with selector .footer a that overrides this 🤔

  2. +++ b/core/profiles/demo_umami/themes/umami/umami.libraries.yml
    @@ -25,6 +25,10 @@ global:
    +      css/components/forms/inputs.css: {}
    +      css/components/forms/select.css: {}
    ...
    +      css/components/forms/textarea.css: {}
    

    It looks like this is adding CSS files that do not exist 🤔

gauravvvv’s picture

Status: Needs work » Needs review
StatusFileSize
new8.79 KB
new1.78 KB

Addressed #63, attached interdiff and patch for same. Please review

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Points have been addressed thanks!

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs manual testing
StatusFileSize
new19.45 KB
new19.39 KB

This needs some more manual testing. There's at least one regression with the search input.

Before:

After:

markconroy’s picture

It looks like the patch is removing all the styling for input but 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.

-input {
-  min-width: 100%;
-  max-width: 100%;
-  margin: 0.25rem 0;
-  padding: 0.8rem 0.4rem;
-  color: #000;
-  border: 2px solid #767775;
-  font-size: 1rem;
-}
-input:focus {
-  border: 2px solid #008068;
-}
-input[type="checkbox"] {
-  min-width: inherit;
-  max-width: none;
-}
-
-textarea {
-  padding: 0.8rem 0.4rem;
-  color: #000;
-  border: 2px solid #767775;
-}
-textarea:focus {
-  border: 2px solid #008068;
-}

kunal_sahu made their first commit to this issue’s fork.

kunal_sahu’s picture

Assigned: Unassigned » kunal_sahu

I am working on this issue , will provide an patch soon. Thanks

markconroy’s picture

Assigned: kunal_sahu » Unassigned

Unassigning.

markconroy’s picture

Status: Needs work » Needs review
StatusFileSize
new218.14 KB
new339.04 KB

A further update to this patch:

  1. Moves the form-element-label.html.twig file from templates > classy to templates > form.
  2. Adds a class of .form-label to all labels and uses this class to theme labels
  3. Adds CSS for textarea via the .form-textarea class
  4. Adds CSS for inputs via the .form-text and .form-email classes
  5. Adds CSS for search results form input via .search-form .form-search class

Side-by-side screenshots of the contact and search pages (the only pages regressed by the previous patch) attached.

umami contact page

umami search page

markconroy’s picture

StatusFileSize
new11.85 KB
new5.21 KB

Sorry, I forgot to upload the patch and interdiff ;-)

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Removing 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.

markconroy’s picture

@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.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Nice to see that this is shaping up! Few small comments that occurred when looking at the patch:

  1. +++ b/core/profiles/demo_umami/themes/umami/css/components/blocks/footer-promo/footer-promo.css
    @@ -16,6 +16,27 @@
    +.footer a.footer-promo-block__link {
    ...
    +.footer a.footer-promo-block__link:focus,
    +footer a.footer-promo-block__link:hover {
    ...
    +.footer a.footer-promo-block__link:after {
    

    Couldn't these selectors be simplified just to .footer-promo-block__link?

  2. +++ b/core/profiles/demo_umami/themes/umami/css/components/forms/form-items.css
    @@ -0,0 +1,48 @@
    +.form-label {
    

    We should add @file documentation here 😇

  3. +++ b/core/profiles/demo_umami/themes/umami/umami.theme
    @@ -39,6 +39,13 @@ function umami_preprocess_field(&$variables, $hook) {
    +        $variables['items'][$key]['content']['#options']['attributes']['class'][] = $bem_element_class;
    

    The block class is added in core/profiles/demo_umami/themes/umami/templates/components/footer-promo-block/block--bundle--footer-promo-block.html.twig which 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 😇

markconroy’s picture

Status: Needs work » Needs review
StatusFileSize
new12.58 KB
new3.4 KB

Thanks @lauriii

We need to leave the .footer a part of the CSS in the footer promo block, or else our css gets overridden by .footer a that is in the footer CSS file.

I've the other items fixed now.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Think this is good to be looked at again.

lauriii’s picture

#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.

markconroy’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new12.64 KB
new1.32 KB

Good tip @lauriii. Thanks. Attached.

Status: Needs review » Needs work

The last submitted patch, 79: 2936875-79.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new138.27 KB

Failure in #79 seems unrelated

Installed a fresh Umami install with patch #79 and the footer seemed to still function

footer

lauriii’s picture

StatusFileSize
new12.26 KB
new2.29 KB

"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.

markconroy’s picture

Looks good to me, thanks @lauriii

  • lauriii committed 161f2015 on 10.1.x
    Issue #2936875 by hiway, markconroy, lauriii, Gauravvvv, smustgrave,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 161f201 and pushed to 10.1.x. Thanks!

markconroy’s picture

Woo hoo! Thanks.

quietone’s picture

Issue tags: -Needs manual testing

Final manual testing was done in #81, removing tag.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.