Suggested commit message

git commit -m 'Issue #2398445 by jp.stacey, LewisNyman, Manjit.Singh, pjbaert, emma.maria, ti2m: Clean up the "elements" component in Bartik'

Problem/Motivation

Bartik's code needs to meet current Drupal coding standards.

Proposed resolution

This issue takes a specific section of Bartik's code, it acts as a "component" issue and improves that section of code with minimal impact on the rest of Bartik's codebase.

This issue aims to clean up and properly format the CSS and templates files without breaking Bartik visually.

This issue primarily looks at the css/base/elements.css file.

Work that needs to be included in patches for this issue are fully outlined in the META issue #1342054: [META] Clean up templates and CSS.

The work needs to be crossed off the list below as completed or stated why they were not applicable to this issue in the comments below, to make sure we cover everything.

Also very helpful! Noting the list items in your comment with the patch to show what parts you added to the patch.

Create a patch containing the potential following work:

Code cleanup work

  1. Check each selector in the CSS file (associated with the particular issue) is in use within core right now.
    If not...
    a) Check to see if the classes in core have been changed and correct them (for e.g. I found this in this issue ).
    or
    b) Remove that CSS completely from the CSS file.
  2. a) Check the CSS selectors are not being replicated in other stylesheets in Bartik.
    b) Check the CSS properties are not being overridden by other stylesheets in Bartik.
    If a) move all of the properties to the selector in the stylesheet that you think most appropriate for the component you are dealing with.
    If a) and b) also remove the CSS properties and values being overridden within that ruleset.
  3. If you find CSS for a component which seems out of place in the file it is currently in move it to the one you think is the correct one.
  4. If a selector appears to be too long and/or too specific, check if the selector can be simplified. for eg. .something .something .something { } being modified to .something .something { }.
  5. Check that RTL styles exist when needed and are formatted as per the guidelines. (for e.g. we found that RTL styles are broken on certain pages in this issue, so fix anything you see missing/incorrect in the CSS file.
  6. If you think the contents of the CSS file could be further broken down into more components CSS files, or grouped together with other existing CSS files to form one component do it. The initial SMACSS issue may not of been perfect, guidelines on CSS file organisation for Drupal 8 can be found here.
  7. Check the markup from the templates that all of the classes are used as selectors in the CSS files. If not remove them. See an example issue here for this.

Code formatting work

  1. Add a File comment to the top of the stylesheet - see here for guidelines.
  2. Check any other comments are formatted correctly - see here for guidelines.
  3. Check Whitespace is being used correctly, this includes indentations and line breaks - see here for guidelines.
  4. Check the formatting of rulesets, properties and media queries are correct - see here for guidelines.
  5. As mentioned above, check existing RTL styles are formatted correctly - see here for guidelines.

Remaining tasks

  • Assess the code applicable to this patch and figure out what work in the lists above need to be included in the patch.
  • Cross out work tasks that do not apply to this issue.
  • Write a patch with as much work as you want to include, upload and comment what you included
  • Review the patch - code review and visual changes
  • Upload screenshots to show nothing/something is broken on the frontend

User interface changes

None, we are cleaning up CSS and markup in templates. The use of Bartik's UI and design will stay the same.

API changes

n/a

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it is a code clean up overhaul of a theme.
Unfrozen changes Unfrozen because it only refactors CSS and templates, no changes to UI or APIs
Prioritized changes The main goal of this issue is usability and performance. We want Bartik code to be up to date and something to be proud of.
Disruption No disruption it's only refactoring code not changing how to use the theme
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

emma.maria’s picture

Title: Clean up elements code in Bartik » Clean up "elements" CSS in Bartik
LewisNyman’s picture

FileSize
1.71 KB

Experimenting with a good way to review the existing code in the file.

LewisNyman’s picture

Sweet! If I upload the css file with a .patch suffix then I can review the code with Dreditor.

  1. /* ---------- Overall Specifications ---------- */
    

    Change this to @file comment, see [#1887862]

  2.   margin: 0;
      padding: 0;
      border: 0;
    

    I think we can remove these lines, as they should be handled by normalize.css

  3. .field-type-image a,
    h1 a,
    h2 a,
    [role*=banner] a,
    .feed-icon,
    .contextual-links a,
    .toolbar a {
      border-bottom: none !important;
    }
    

    This kind of selector group is against one of the SMACSS principles which is to keep all styling affecting one component in one place. All these selectors should be moved to the correct file.

  4. h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      margin: 1.0em 0 0.5em;
      font-weight: inherit;
    }
    h1 {
      font-size: 1.357em;
      color: #000;
    }
    h2 {
      font-size: 1.143em;
    }
    h3 {
      font-size: 1.092em;
    }
    h4 {
      font-size: 1.05em;
    }
    h5 {
      font-size: 0.889em;
      text-transform: uppercase;
      letter-spacing: 0.1em;
    }
    h6 {
      font-size: 0.67em;
      text-transform: uppercase;
      letter-spacing: 0.1em;
    }
    

    In Seven, we've added .header-a,.header-b,.header-c,.header-d,.header-e classes that match up with the equivalent header styles. Feels like we should add them here as well.

  5. /* ------------------ Reset Styles ------------------ */
    

    Remove this, these aren't reset styles

  6. a.feed-icon {
      display: inline-block;
      padding: 15px 0 0 0;
    }
    

    This should go into it's own component file

emma.maria’s picture

Title: Clean up "elements" CSS in Bartik » Clean up the "elements" component in Bartik
jp.stacey’s picture

Assigned: Unassigned » jp.stacey

Having a look at this now.

jp.stacey’s picture

Status: Active » Needs work
FileSize
4.49 KB

I don't think the standalone CSS file in #3 is current enough any more to just drop in and work from it: 8.0.x is too much of a moving target. For example, just dropping it in loses the fonts!

With that in mind, I've uploaded a patch/diff file as a starting point for discussion instead. I've tried to follow as many as possible of the recommendations here, but it would be good if it could be reviewed critically by those who know SMACSS, BEM and core standards better than me.

A lot of the changes between #3 and HEAD seem to have come from other Bartik tidyups, so I mention them below to indicate that I've not omitted them just because I felt like it:

Anyway, comments welcome.

jp.stacey’s picture

Assigned: jp.stacey » Unassigned

Unassigning. I knew there was a select dropdown I'd forgotten to change :)

jp.stacey’s picture

Status: Needs work » Needs review
FileSize
4.48 KB

The patch in #6 no longer cleanly applies as 8.0.x is a moving target. I've re-rolled against HEAD and attached a patch.

These seem to be quite small changes: can anyone see anything wrong with them that might block them?

Manjit.Singh’s picture

@jp.stacey Everything looks fine in patch :)

Adding Description of file in header.css

/**
 * @file
 * Header styles for Bartik.
 */
jp.stacey’s picture

@Manjit thanks for reviewing the patch and confirming it applies.

Regarding your addition of the header.css @file comment. I've just opened #2466983: Clean up the "header" component in Bartik to track changes to header.css and added a mention of your suggestion. That other issue needs improving to use the standard template, but for now it's a good placeholder for your suggestion.

This issue should ideally only track changes to elements.css (unless those changes entail changes to other files, to make sure we don't lose styling by deleting it.)

LewisNyman’s picture

Status: Needs review » Needs work

Regarding your addition of the header.css @file comment. I've just opened #2466983: Clean up the "header" component in Bartik to track changes to header.css and added a mention of your suggestion.

Yep that sounds like a good idea, we should keep changes focused on one file per issue.

+++ b/core/themes/bartik/css/base/elements.css
@@ -28,19 +28,14 @@ a:focus,
+h2 a {
+  border-bottom: none important;

+++ b/core/themes/bartik/css/components/content.css
@@ -154,6 +154,9 @@ h1#page-title {
+.field-type-image a {
+  border-bottom: none !important;

+++ b/core/themes/bartik/css/components/contextual.css
@@ -1,8 +1,14 @@
 .contextual-region .contextual .contextual-links a {
+  border-bottom: none !important;

I'm unsure that these !important properties are required and I think we should avoid them if we can.

We can also run csslint against this file to see if it passes. The easiest way to run this test is using: https://github.com/lewisnyman/drupalcore-frontend-toolkit

jp.stacey’s picture

Assigned: Unassigned » jp.stacey

@LewisNyman thanks for that: looking at your feedback now.

jp.stacey’s picture

This is still work in progress, but the patch and interdiff attached details improvements so far.

To test why !important declarations were required, I set up an image field on basic page, which is display-formatted to link to the original image. I created some content, with an image, and set it to be promoted to the front page.

The following !important are all intended to remove border-underline from elements but are NOT REQUIRED:

  • elements.css: h2 a (linked teaser titles on e.g. the front page)
  • content.css: .field-type-image a (linked images on e.g. the node page itself)
  • contextual.css: .contextual-region .contextual .contextual-links a (contextual links e.g. quickedit links)
  • feed-icon.css: .feed-icon (RSS feed icon on e.g. the front page)
  • header.css: [role*=banner] a (links in the page header element e.g. top-right menu links)
  • toolbar.css: .toolbar a (links in the admin toolbar)

I've therefore removed these. I've also removed an extra !important in contextual.css, in the same selector as the declaration added as part of this ticket: the rule removes text-shadow from those links, but still works without it.

Finally, I've also checked elements.css for other !important declarations, and there are none. Hooray!

I'll now look at running CSSLint over elements.css and any files created by the patch.

LewisNyman’s picture

Assigned: jp.stacey » Unassigned
Status: Needs work » Needs review

Settings to needs review so we can get some feedback

The last submitted patch, 6: clean-up-bartiks-elements-2398445-6.patch, failed testing.

jp.stacey’s picture

To confirm, @LewisNyman has CSSLint'ed the relevant files (discussed on IRC) and they're looking good. Also attempting with this comment to change my attribution to include my company :)

LewisNyman’s picture

I'm going over the element.css file for more improvements we can make

blockquote:before {
  color: #bbb;
  content: "\201C";
  font-size: 3em;
  line-height: 0.1em;
  margin-right: 0.2em; /* LTR */
  vertical-align: -.4em;
}

We should have vertical-align: -0.4em

blockquote:after {
  color: #bbb;
  content: "\201D";
  font-size: 3em;
  line-height: 0.1em;
  vertical-align: -.45em;
}

We should have vertical-align: -0.45em

img {
  max-width: 100%;
  height: auto;
  border: 0;
}

Maybe we don't need border: 0? It feels like that would be covered in normalise

a {
  text-decoration: none;
  border-bottom: 1px dotted;
}

I think this selector also needs the .link class as we include it in the css below.

body {
  min-height: 100%;
  line-height: 1.5;
  word-wrap: break-word;

I'm unsure why we have word-wrap: break-word up here. Maybe we should leave it to be sure but I've never seen this in a body tag before

LewisNyman’s picture

Status: Needs review » Needs work
jp.stacey’s picture

Status: Needs work » Needs review
FileSize
5.05 KB
968 bytes

Done:

* -.4em => -0.4em
* -.45em => -0.45em
* img { border: 0; } (indeed covered by normalize.css, so removed)
* a { ... } (included a.link along with a)

The remaining item:

* body { word-wrap: break-word}

- I think we should leave this as it is. It's a way of preventing long URLs from breaking layout, and it was in the old bartik styles.css back in December when SMACSS was applied (e6afbff, #2375673: Split Bartik's CSS into SMACSS style components). So it has a pedigree, which isn't quite the same as saying it adds value ;)

Find patch/interdiff attached.

LewisNyman’s picture

Sounds good to me, I think this issue could benefit from some visual regression testing because it affects so many elements on so many pages

ti2m’s picture

I ran the patch through siteeffect, checked up on 450 urls and couldn't find any visual changes.

emma.maria’s picture

Status: Needs review » Needs work
Issue tags: +Novice
FileSize
1.3 MB

I created and compared node content before and after applying the patch in #19. Elements.css applies styles to much of the content a user can create. I found no regressions. See file attached for tests.

The one last thing that needs work is that a blank line needs to be added after the file comment at the top of the file...

/**
 * @file
 * Overall specifications for Bartik.
 */
html {
  height: 100%;
}

See the https://www.drupal.org/node/1887862/#file-comments for more details.

Tagging with Novice. Take the patch in #19 and create a new patch with the blank line included as indicated above.

pjbaert’s picture

Status: Needs work » Needs review
FileSize
5.05 KB

Added the blank line after the file comment as asked in #22

emma.maria’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
321 bytes

@pjbaert In future could you please also create an interdiff when you write a patch - https://www.drupal.org/documentation/git/interdiff
This allows people to quickly check for differences between patches and not have to repeat manual testing to check if something was added to the new patch by mistake.
Thanks!

I have created an interdiff between the patches in #19 and #23. The only difference is an extra line as required by my review in #22.

Setting this issue to RTBC. Thanks all!

emma.maria’s picture

Issue tags: +drupaldevdays
emma.maria’s picture

Issue summary: View changes

Suggested commit message

git commit -m 'Issue #2398445 by jp.stacey, LewisNyman, Manjit.Singh, pjbaert, emma.maria, ti2m: Clean up the "elements" component in Bartik'

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5a46466 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

+++ b/core/themes/bartik/css/base/elements.css
@@ -28,19 +30,14 @@ a:focus,
-  border-bottom: none !important;

+++ b/core/themes/bartik/css/components/contextual.css
@@ -1,10 +1,16 @@
-  text-shadow: 0 0 0 !important;

Less importance!!! nice :)

  • alexpott committed 5a46466 on 8.0.x
    Issue #2398445 by jp.stacey, LewisNyman, Manjit.Singh, pjbaert, emma....

Status: Fixed » Closed (fixed)

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