Follow-up to #2409653: The color module lock/unlock link is not accessible

Problem/Motivation

The color module CSS files are not inline with our CSS standards, and contain quite a few CSSlint errors: http://lewisnyman.co.uk/drupalcore-frontend-toolkit/

Proposed resolution

Refactor the CSS so it fits our standards and produces no CSSlint errors

This issue also uncovered a regression in the UI that was fixed while rewriting the CSS selectors.

Before

After

Remaining tasks

User interface changes

A fix to a UI regression, see above.

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because coding standards
Unfrozen changes Unfrozen because it only changes CSS/markup
CommentFileSizeAuthor
#60 46-57-interdiff.txt522 bytesalexpott
#58 drupal_color-module-css_2470069_57_0.patch24.7 KBmanjit.singh
#57 Screen Shot 2015-04-30 at 14.30.32.png82.17 KBalexpott
#57 Screen Shot 2015-04-30 at 14.32.17.png75.38 KBalexpott
#47 interdiff-42-46.txt313 bytespjbaert
#46 drupal_color-module-css_2470069_46_0.patch24.75 KBmanjit.singh
#43 interdiff-patch29-patch42.txt3.25 KBpjbaert
#42 drupal_color-module-css_2470069_42.patch24.72 KBpjbaert
#36 drupal_color-module-css_2470069_36.patch22.96 KBmanjit.singh
#29 drupal_color-module-css_2470069_29.patch24.79 KBwadmiraal
#29 interdiff.txt415 byteswadmiraal
#25 Screenshot 2015-04-15 16.20.16.jpg301.34 KBlewisnyman
#25 Screenshot 2015-04-15 16.20.01.jpg424.03 KBlewisnyman
#24 interdiff.txt397 byteswadmiraal
#24 drupal_color-module-css_2470069_24.patch24.79 KBwadmiraal
#21 Screenshot 2015-04-15 14.16.35.jpg81.6 KBlewisnyman
#21 Screenshot 2015-04-15 14.17.26.jpg158.28 KBlewisnyman
#20 interdiff.txt380 byteswadmiraal
#20 drupal_color-module-css_2470069_20.patch24.77 KBwadmiraal
#19 color-locks.png138.69 KBwadmiraal
#18 interdiff.txt1.05 KBwadmiraal
#18 drupal_color-module-css_2470069_17.patch24.77 KBwadmiraal
#16 color-d7.png57.34 KBwadmiraal
#14 Screenshot 2015-04-14 16.28.53.jpg477.88 KBlewisnyman
#14 Screen Shot 2015-04-14 at 16.28.31.jpg477.14 KBlewisnyman
#14 Screenshot 2015-04-14 16.27.51.jpg473.7 KBlewisnyman
#13 interdiff.txt1.11 KBwadmiraal
#13 drupal_color-module-css_2470069_13.patch24.08 KBwadmiraal
#12 interdiff.txt6.21 KBwadmiraal
#12 drupal_color-module-css_2470069_12.patch24.08 KBwadmiraal
#9 interdiff.txt5.28 KBwadmiraal
#9 drupal_color-module-css_2470069_9.patch23.99 KBwadmiraal
#7 interdiff.txt3.98 KBwadmiraal
#7 drupal_color-module-css_2470069_7.patch23.99 KBwadmiraal
#6 color_css_refactor_2470069.patch29.78 KBzakxxi
#3 drupal_color-module-css_2470069_3.patch21.08 KBwadmiraal

Comments

lewisnyman’s picture

Issue summary: View changes
wadmiraal’s picture

Assigned: Unassigned » wadmiraal

Having a look it.

wadmiraal’s picture

Status: Active » Needs review
StatusFileSize
new21.08 KB

Removed all CSS ID selectors from the the Color module CSS files. This has an impact on JS logic as well as on Bartik, which implements the color logic.

Instead of simply re-using the ID as a class (e.g.: #placeholder to .placeholder), I prefixed them with color- (.color-placeholder). I'm afraid just using the class is too generic, and might apply styles in contexts they were not intended for.

lewisnyman’s picture

Status: Needs review » Needs work

Nice! This is going well.

  1. +++ b/core/modules/color/color.js
    @@ -21,8 +21,8 @@
    +      $('<div class="color-placeholder"></div>').once('color').prependTo(form);
    +      var farb = $.farbtastic('.color-placeholder');
    
    @@ -39,8 +39,8 @@
    +          $('.color-preview').once('color').append('<div id="gradient-' + i + '"></div>');
    +          var gradient = $('.color-preview #gradient-' + i);
    
    @@ -198,7 +198,7 @@
    +      form.find('.color-palette input.form-text')
    
    @@ -246,7 +246,7 @@
    +      form.find('.color-palette label');
    
    +++ b/core/themes/bartik/color/preview.js
    @@ -11,35 +11,35 @@
    +        $('.color-preview .color-preview-logo img').attr('src', drupalSettings.color.logo);
    ...
    +        $('div').remove('.color-preview-logo');
    ...
    +      form.find('.color-preview').css('backgroundColor', $('.color-palette input[name="palette[bg]"]').val());
    ...
    +      form.find('.color-preview .color-preview-main h2, .color-preview .preview-content').css('color', form.find('.color-palette input[name="palette[text]"]').val());
    +      form.find('.color-preview .color-preview-content a').css('color', form.find('.color-palette input[name="palette[link]"]').val());
    ...
    +      form.find('.color-preview .color-preview-sidebar .color-preview-block').css('background-color', form.find('.color-palette input[name="palette[sidebar]"]').val());
    +      form.find('.color-preview .color-preview-sidebar .color-preview-block').css('border-color', form.find('.color-palette input[name="palette[sidebarborders]"]').val());
    ...
    +      form.find('.color-preview .color-preview-footer-wrapper', form).css('background-color', form.find('.color-palette input[name="palette[footer]"]').val());
    ...
    +      var gradient_start = form.find('.color-palette input[name="palette[top]"]').val();
    +      var gradient_end = form.find('.color-palette input[name="palette[bottom]"]').val();
    ...
    +      form.find('.color-preview .color-preview-header').attr('style', "background-color: " + gradient_start + "; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(" + gradient_start + "), to(" + gradient_end + ")); background-image: -moz-linear-gradient(-90deg, " + gradient_start + ", " + gradient_end + ");");
    ...
    +      form.find('.color-preview .color-preview-site-name').css('color', form.find('.color-palette input[name="palette[titleslogan]"]').val());
    

    For all the classes that are required by Javascript, we should prefix the class with .js-. See https://www.drupal.org/node/1887918#formatting

    /**
     * Functional JavaScript Hooks
     *
     * When querying or manipulating the DOM from JavaScript, prefer dedicated 
     * classes not used for styling (or the id attribute). 
     * If using classes, prefix them with 'js-' to mark them for JS use. 
     * These 'js-' classes should not appear in stylesheets.
     */
    .js-behaviour-hook  /* e.g. .js-slider, .js-dropdown */
  2. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    -#palette .hook {
    +.color-palette .hook {
    

    .color-palette is a good idea, it is less generic. What we want to do here is to make all the selectors really short, so we could rename this class to .color-palette__hook

  3. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .down,
    

    .color-palette__down

  4. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .up,
    

    .color-palette__up

  5. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .both {
    

    .color-palette__both

  6. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .lock {
    

    .color-palette__lock

  7. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .unlocked {
    

    .color-palette__unlocked

wadmiraal’s picture

Brilliant, love the BEM notation. On it.

zakxxi’s picture

StatusFileSize
new29.78 KB

Hi,

I have also started to work on it, and on the Bartik side wich is linked,
maybe we need to create a Bartik issue for the "preview" part of color module on the theme settings because a lot of work to do here.

wadmiraal’s picture

StatusFileSize
new23.99 KB
new3.98 KB

Refactored, using is-* for state. There are no JS only classes; they all relate to presentation, so we shouldn't use js-* classes in this particular case.

wadmiraal’s picture

Status: Needs work » Needs review

Status change. Sorry, interdiff and patch in #7 did not take #6 into account.

wadmiraal’s picture

StatusFileSize
new23.99 KB
new5.28 KB

Sorry, interdiff is incorrect I see. Re-rolling patch from #7, correcting interdiff.

lewisnyman’s picture

Status: Needs review » Needs work

Good stuff

  1. +++ b/core/modules/color/color.js
    @@ -198,7 +198,7 @@
    +      form.find('.color-palette input.form-text')
    
    @@ -236,17 +236,17 @@
    +      form.find('.color-palette label');
    
    +++ b/core/modules/color/templates/color-scheme-form.html.twig
    @@ -17,7 +17,7 @@
    -  <div id="palette" class="clearfix">
    +  <div class="clearfix color-palette">
    

    I think the only class that is required by javascript is this only, so we would only need to add another class that we only use to init the JS: js-color-palette

  2. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .is-down,
    +.color-palette .is-up,
    +.color-palette .is-both {
    

    In this situation I think that we would use the common class .color-palette__hook to apply the background image.

  3. +++ b/core/modules/color/css/color.admin.css
    @@ -27,56 +27,56 @@
    +.color-palette .is-up {
    ...
    +.color-palette .is-both {
    

    When we do this we should also include the component in the selector. So it would be:

    .color-palette__hook.is-up
    .color-palette__hook.is-both
    

    etc

wadmiraal’s picture

On it.

wadmiraal’s picture

Assigned: wadmiraal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new24.08 KB
new6.21 KB

Updated.

Switching to .js-color-palette is a good idea, but just be aware Bertik adds a small CSS rule for the form, so now uses js-color-palette. It's small, and the standards say we "shouldn't" use js-* classes in CSS, but that doesn't mean there are no, very rare, cases where we can. Here, for example, the basic color component works fine without any additional styling. Only Bartik adds a slight margin and positioning to make it look a little better.

Or we add a double class, .color-palette.js-color-palette ...

wadmiraal’s picture

StatusFileSize
new24.08 KB
new1.11 KB

Applied the double CSS class approach (.js-color-palette and .color-palette).

lewisnyman’s picture

Status: Needs review » Needs work
StatusFileSize
new473.7 KB
new477.14 KB
new477.88 KB

I manually tested this patch and found the up/down behaviour is a bit different from before. It seems to be adding the lines to the wrong elements. See the screenshots:

Before:

After:

wadmiraal’s picture

Status: Needs work » Needs review

Yes, I noticed. I opened a separate issue here: #2470769: Color module lock hooks don't show up correctly. This bug is not related to the class changes. Checking out on 8.0.x reveals the same problem. There's already a patch in the linked issue.

In fact, your first screenshot already shows the bug; it's not correctly showing the lines at the third locked lock. Now that I look closer, the locks are actually too low. A lock should sit between 2 fields, not next to a field.

wadmiraal’s picture

StatusFileSize
new57.34 KB

Here's a screenshot of D7. The difference with your "before" screenshot is quite clear:

Color module in D7

wadmiraal’s picture

Assigned: Unassigned » wadmiraal
Status: Needs review » Needs work

Ok, patch doesn't apply anymore; HEAD has moved. Plus, new HEAD introduces another bug (lock icons not showing up anymore).

wadmiraal’s picture

Assigned: wadmiraal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new24.77 KB
new1.05 KB

We need to be careful. Color module and Bartik are being updated elsewhere as well. Latest HEAD broke the lock icons. I fixed it in this patch (check interdiff). Also, the locks were not correctly aligned. I fixed it here as well, instead of opening yet another issue.

wadmiraal’s picture

StatusFileSize
new138.69 KB

For reference, here's the state after applying patch in #18:

After patch 18

The hooks are still incorrect, see #2470769: Color module lock hooks don't show up correctly.

wadmiraal’s picture

StatusFileSize
new24.77 KB
new380 bytes

Fixing small syntax issue.

lewisnyman’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new158.28 KB
new81.6 KB

I manually tested this patch and it seems like the lock UI is still buggy, it's still not drawing the lines between the right locks?

Also I ran the patched code through CSS lint and we only have one left in color.admin.css:

lewisnyman’s picture

I think that all the Javascript is broken, I'm not sure why yet though.

wadmiraal’s picture

Assigned: Unassigned » wadmiraal

As noted in #15 and #19, the JavaScript has an error, it is reported here #2470769: Color module lock hooks don't show up correctly and the issue already has a patch.

I'll fix the text-indent issue while we're at it.

wadmiraal’s picture

Assigned: wadmiraal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new24.79 KB
new397 bytes

Here we go again :-)

lewisnyman’s picture

Issue summary: View changes
StatusFileSize
new424.03 KB
new301.34 KB

Great! Functionally this works as it did before, and you are right about the lock line issue already existing in here. We have no CSSlint errors now! Here are some screenshots to show that the color module integration is working correctly with Bartik.


lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

I think I meant to RTBC this. Sorry.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: drupal_color-module-css_2470069_24.patch, failed testing.

wadmiraal’s picture

Assigned: Unassigned » wadmiraal

Ok, HEAD moved. Re-rolling patch.

wadmiraal’s picture

Assigned: wadmiraal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new415 bytes
new24.79 KB

Ok, re-rolled.

lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

Nice, thanks.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: drupal_color-module-css_2470069_29.patch, failed testing.

Status: Needs work » Needs review
lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: drupal_color-module-css_2470069_29.patch, failed testing.

lewisnyman’s picture

Issue tags: +Needs reroll
manjit.singh’s picture

Issue tags: -Needs reroll
StatusFileSize
new22.96 KB

@LewisNyman Please verify the patch.

lewisnyman’s picture

Status: Needs work » Needs review
lewisnyman’s picture

Status: Needs review » Needs work

It looks like the most recent patch is missing the changes to the color module preview.js

The last submitted patch, 29: drupal_color-module-css_2470069_29.patch, failed testing.

pjbaert’s picture

Patch #36 was indeed missing the changes to the color module preview.js

I could apply patch 29 without any problems so I queued #29 for a re-test.

pjbaert’s picture

Status: Needs work » Needs review
StatusFileSize
new24.72 KB

Please ignore the last part of my previous comment :)

I re-rolled patch #29

pjbaert’s picture

StatusFileSize
new3.25 KB

Added the interdiff between patch 29 & 42

lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

Ok great! This looks good. Thanks.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/color/css/color.admin.css
@@ -27,57 +28,68 @@
+/**
+ * The button also inherits from .link, which hides the background. Use a more
+ * specific selector to overwrite.
+ */
+button.color-palette__lock,
+.color-palette__lock {
...
-[dir="rtl"] #palette .lock {
+[dir="rtl"] .color-palette__lock {

I guess the rtl version needs the more specific selector too.

manjit.singh’s picture

StatusFileSize
new24.75 KB

@alexpott Please verify the patch now.

pjbaert’s picture

Status: Needs work » Needs review
StatusFileSize
new313 bytes

Thanks for the updated patch @Manjit.Singh
I added an interdiff to show the difference between patch #42 & yours.

To me, this patch looks fine since you added the more specific selector @alexpott asked for in #45.

lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

I had a quick look over the patch to make sure we haven't missed any other RTL changes and I couldn't see any. Thanks! This will bring our CSSlint error count down by about 85 errors :)

pjbaert’s picture

Status: Reviewed & tested by the community » Needs work

I noticed we still have to delete this '\ No newline at end of file'

diff --git a/core/modules/color/preview.html b/core/modules/color/preview.html
index e25b7ad..d89edcb 100644
--- a/core/modules/color/preview.html
+++ b/core/modules/color/preview.html
@@ -1,7 +1,7 @@
-<div id="preview">
+<div class="color-preview">
   <div id="text">
     <h2>Lorem ipsum dolor</h2>
     <p>Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud <a href="#">exercitation ullamco</a> laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
   </div>
   <div id="img"></div>
-</div>
\ No newline at end of file
+</div>
manjit.singh’s picture

@pjbaert but if you check it manually there is a blank line after </div>.

pjbaert’s picture

Status: Needs work » Reviewed & tested by the community

:) you're right. I checked this manually.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

I can't wait to be able to use csslint to test all commits that change CSS.

Committed 1ea7b90 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed 1ea7b90 on 8.0.x
    Issue #2470069 by wadmiraal, Manjit.Singh, pjbaert, zakxxi, LewisNyman:...

  • alexpott committed f990ca6 on 8.0.x
    Revert "Issue #2470069 by wadmiraal, Manjit.Singh, pjbaert, zakxxi,...
alexpott’s picture

Status: Fixed » Needs work
+++ b/core/modules/color/css/color.admin.css
@@ -27,57 +28,68 @@
+/**
+ * The button also inherits from .link, which hides the background. Use a more
+ * specific selector to overwrite.
+ */
+button.color-palette__lock,
+.color-palette__lock {
...
-[dir="rtl"] #palette .lock {
+[dir="rtl"] .color-palette__lock {

Hmmm... the rtl variant is still missing for the more specific selector this patch adds.

alexpott’s picture

+++ b/core/modules/color/css/color.admin.css
@@ -104,17 +116,18 @@
-  #palette .lock {
+  button.color-palette__lock,
+  .color-palette__lock {
     float: left; /* LTR */
   }
-  [dir="rtl"] #palette .lock {
+  [dir="rtl"] .color-palette__lock {
     float: right;
   }

This can be removed it is the same as the default styling.

alexpott’s picture

Also the current patch completely messes up the form - it's a regression from head.

Patch

Head

manjit.singh’s picture

StatusFileSize
new24.7 KB
alexpott’s picture

Status: Needs work » Needs review

Okay I see from #16 that we fixing a regression from Drupal 7 here already. I think that fixing that here is scope creep but I guess we can let that slide to get this done. So #57 is not an issue but #55 and #56 are because the scope of this issue is to Refactor color module CSS inline with our CSS standards. #55 would be a regression introduced by the patch and #56 is part of the don't have unnecessary duplicate CSS that if it is not part of our standard - it should be.

Can the usability fix introduced by the patches subsequent to #16 by documented on the issue summary. Thanks.

alexpott’s picture

StatusFileSize
new522 bytes

Posting the interdiff of 46 to 58. Looks good.

alexpott’s picture

Adding the followup to fix the hook display to the related issues.

lewisnyman’s picture

lewisnyman’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Ok great, I've updated the issue summary to include the UI fix. Thanks.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 271766e and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed 271766e on
    Issue #2470069 by wadmiraal, Manjit.Singh, pjbaert, zakxxi, LewisNyman:...

Status: Fixed » Closed (fixed)

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