Download & Extend

Simplify names of "element-x" helper classes

Project:Drupal core
Version:8.x-dev
Component:CSS
Category:task
Priority:normal
Assigned:mparker17
Status:needs work
Issue tags:accessibility, html5, JavaScript

Issue Summary

Something that has really bothered me since these classes were originally introduced is how overly verbose they are. I see no reason these classes need to be so verbose and would like to see them follow the HTML5 Boilerplate.

Before After
element-hidden hidden
element-invisible visuallyhidden
element-focusable visuallyhidden.focusable
invisible

Comments

#1

Status:active» needs review

And here's a patch that does that.

AttachmentSizeStatusTest resultOperations
1363112-01-simplify-element-x-classes.patch28.41 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1363112-01-simplify-element-x-classes.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#2

Issue tags:+accessibility

Tagging. The patch only changes the names of the classes, but the accessibility team should be aware.

#3

In theory I am in support of the change. You really wouldn't believe how much time and effort was spent on building consensus around the current names :) So, as long as all supporting documentation can be cleaned up for D8, and if the patch doesn't miss anything, then +1 from me!

#4

What about allowing both the new short names and the older, longer names?

The patch could be more like this:

-.element-hidden {
+.hidden, .element-hidden {
   display: none;
}

We've spent lots of energy teaching themers to use "element-invisible" rather than "display:none". I would suggest we keep those old class names working. That would be less upgrade effort when themers move from D7 to D8.

#5

Sure, that's possible (and if it was the last choice, I'd settle for it) but I'd really prefer we that didn't. We are changing all sorts of things about Drupal 8, from markup to CSS to API's, etc... We don't really do this sort of thing - babysitting old/bad code - for upgrade purposes.

In reality it would literally be a quick find and replace fix that would be listed in the upgrade guide. This patch took no more than 10 minutes for me to roll for all of core. It's pretty rare that themes are upgradable for major versions and the worst case scenario here is that elements that are supposed to be invisible will appear and most module developers will notice that immediately and be able to reference it in the upgrade guide.

I hated these classes since I first laid eyes on them, but didn't want to bikeshed and prevent the issues from going forward because they had been going on for a very long time before I got involved. AFAIC, It's completely asinine to have a "element-" prefix on a class, because classes are FOR elements. LOL. It reminds me of the whole "clear-block" vs. "clearfix" thing all over again.

Also... This is sorta related on the documentation/blog post front - The current code for the element-invisible class is totally buggy. I'm not using this code in my themes because it has too many visual issues. I'm currently using this version. It needs to be fixed and so will any documentation or blog posts that reference it. Basically, it's not exactly a model example that is set in stone right now.

#6

@Jacine, that's fine with me. As long as we document this change for D8, I agree with you that it is a search-and-replace solution.

#7

Thanks for the feedback @bowersox! We would definitely document it. It would need a change notification after being committed. :)

#8

Really have to echo this "You really wouldn't believe how much time and effort was spent on building consensus around the current names :)" - the name change would certainly make it easier to remember. We need to get back to why we went with element-x in the first place though. This was brought in by here:
http://drupal.org/node/473396#comment-1828830

To quote @sun:

"The only possible issue I can see with those two generic CSS class names is that an arbitrary module might want to integrate a third-party library (such as an wysiwyg editor) or even simply imports content from another system, where one of those classes had a completely different meaning. In both cases, user interface or content elements will vanish mysteriously. And, we cannot alter these classes later on, because many themes/modules/sites will depend on them. However, using a prefix for them might as well be strange."

I do think we need to give some thought about how we look at this for D8. I've got a thread here with issues to discuss:
http://groups.drupal.org/node/120224

#9

"The only possible issue I can see with those two generic CSS class names is that an arbitrary module might want to integrate a third-party library (such as an wysiwyg editor) or even simply imports content from another system, where one of those classes had a completely different meaning. In both cases, user interface or content elements will vanish mysteriously. And, we cannot alter these classes later on, because many themes/modules/sites will depend on them. However, using a prefix for them might as well be strange."

This is an edge case IMO. And using a prefix for any plugin/widget is a best practice. Trying to protect against a situation like that is the definition of babysitting bad code, and it's probably the reason why so many of our classes are excessive and convoluted.

Thinking about this more, I think we should just do the same thing that H5BP does, except use .visually-hidden (with a dash):

/* Hide from both screenreaders and browsers: h5bp.com/u */
.hidden { display: none !important; visibility: hidden; }

/* Hide only visually, but have it available for screenreaders: h5bp.com/v */
.visuallyhidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; }

/* Extends the .visuallyhidden class to allow the element to be focusable when navigated to via the keyboard: h5bp.com/p */
.visuallyhidden.focusable:active, .visuallyhidden.focusable:focus { clip: auto; height: auto; margin: 0; overflow: visible; position: static; width: auto; }

/* Hide visually and from screenreaders, but maintain layout */
.invisible { visibility: hidden; }

There is no way to confuse those class names. And visually-hidden is a MUCH better descriptive class name than invisible anyway. As you can see invisible does have a different meaning. There are a slew of people using this code right now. If there were complaints about class name clashes they would have addressed them by now.

I really do think this is an edge case issue and that we need to stop bikeshedding and think about what we want to see here for D8. I want Drupal to be more inline with what is being done in the web standards community. Certain things need to be intuitive and make more sense to developers, and this is one of them.

People literally gave up because there was so much bikeshedding going on. That's why we have this prefix IMO, and I don't think we should keep it, or have that whole bikeshed discussion all over again. We should just think about what the best class is for each, and IMO it's what is pasted above.

#10

I feel that there is too high a probability of collision here if we move to shorter names. Given the large number of libraries and other things that are pulled into Drupal, there is a good chance that these would collide with something, especially since JS stuff is often hiding/showing things and hence quite likely to hit on these terms (and traditionally often bad at namespacing, especially in css).

#11

Can someone please go find some examples of actual collisions?

Maybe we should just prefix all of our classes with drupal-. Then we will be safe. Sigh.

#12

I agree with Jacine’s suggestion on using the same class names as the HTML5 Boilerplate.

@Owen I'm not too worried about collisions—most 3rd-party widgets and libraries namespace they're css selectors.

#13

Status:needs review» needs work

Marking this needs work to incorporate the H5BP names into the patch.

#14

+1 for same class names as the HTML5 Boilerplate. Makes perfect sense.
Cleaner, clearer and more elegant.

#15

Status:needs work» needs review

#1: 1363112-01-simplify-element-x-classes.patch queued for re-testing.

#16

Status:needs review» needs work

The last submitted patch, 1363112-01-simplify-element-x-classes.patch, failed testing.

#17

Status:needs work» needs review

I firmly agree with dropping the element- prefix, this makes things so much cleaner and just *makes sense*. I re-rolled the patch from #1 to cleanly apply to current 8.x HEAD.

AttachmentSizeStatusTest resultOperations
simplify-element-classes-1363112.patch28.76 KBIdleFAILED: [[SimpleTest]]: [MySQL] 35,591 pass(es), 90 fail(s), and 0 exception(s).View details | Re-test

#18

Status:needs review» needs work

The last submitted patch, simplify-element-classes-1363112.patch, failed testing.

#19

Status:needs work» needs review

I have resolved the issues that made the patch in #17 fail and re-rolled.

AttachmentSizeStatusTest resultOperations
simplify-element-classes-1363112-19.patch27.86 KBIdlePASSED: [[SimpleTest]]: [MySQL] 35,700 pass(es).View details | Re-test

#20

The patch in #19 looks good to me using Stark, Bartik, and Seven.

I tested in Linux and Mac on Chrome, Safari, and Firefox. I haven't tested it in Windows or IE.

#21

Status:needs review» reviewed & tested by the community

Downloaded and applied the patch, no failures. Since we're just altering class names I'm gonna go ahead and make this RTBC.

#22

Category:feature request» task
Status:reviewed & tested by the community» needs work

This is not using the H5BP names as suggested in #13, and I think that was a good idea, so moving back to needs work.

#23

Status:needs work» needs review

This patch changes the invisible class to visually-hidden. It also fixes documentation issues and an incorrect jQuery selector in overlay-child.js.

AttachmentSizeStatusTest resultOperations
simplify-element-classes-1363112-23.patch30.65 KBIdlePASSED: [[SimpleTest]]: [MySQL] 35,802 pass(es).View details | Re-test

#24

@Everett Zufelt pinged @Jacine about this, and they both feel we should exactly match the HTML5 Boilerplate naming convention. So the name should be "visuallyhidden" without a hyphen. The whole idea is that we match HTML5 Boilerplate exactly because so much existing code is written against that. I am also comfortable with this.

@dcmouyard, thanks for moving this forward!

#25

Issue tags:+JavaScript

tag

#26

Re-roll of 25. The only difference is the name is now "visuallyhidden" rather than "visually-hidden", in order to match HTML5 Boilerplate exactly. Also a few whitespace changes removed.

Please review and test. Make sure to clear all caches after applying the patch. Verify that the invisible stuff still works right -- like the Skip to main content link and the visually hidden text on active vertical tabs, for example. It works for me in Firefox 12 and Safari 5.

AttachmentSizeStatusTest resultOperations
simplify-element-classes-1363112-26.patch30.07 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch simplify-element-classes-1363112-26.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#27

Patch from #26 looks great! Applies cleanly and makes exact changes as described. I fully support this class the idea to adopt boilerplate's naming convention, the less 'unique' instances for stuff like this we have in core, the easier it becomes for new comer's to Drupal to get understand become familar.

Would be nice to get some other eyes on this and mark RTBC.

#28

What's the benefit of matching the exact class name HTML5 Boilerplate uses? How often does 3rd-party code uses the HTML Boilerplate naming convention?

The Drupal coding standard states words should be separated by dashes in css classes.

#29

#28

What's the benefit of matching the exact class name HTML5 Boilerplate uses? How often does 3rd-party code uses the HTML Boilerplate naming convention?

The benefit is following a standard that is already laid out in one of the webs most popular (and forward thinking) front-end frameworks. The less drupalisms we have, the easier it is for people who are already familiar with other frameworks to understand whats being done and how to extend it. Plus - I don't see anything in the coding standards that talks about words having to be separated by dashes. I only remember hearing talk of using dashes over underscores in class names.

CSS Standard: http://drupal.org/node/302199
Markup Standard: http://groups.drupal.org/node/6355

#30

Regardless if there may be a Drupal standard stating that ashes are preferred / required, we have buyin from Core markup / accessibility maintainers to special case for this limited use-case. The benefit is not only for existing code, but existing understanding and future training.

#31

#33

Status:needs review» needs work

The last submitted patch, simplify-element-classes-1363112-26.patch, failed testing.

#32

The last submitted patch, simplify-element-classes-1363112-26.patch, failed testing.

#34

Status:needs work» needs review

What needs to be done to mark this RTBC?

1) Apply patch, clear cache & look for instances where element-invisible was previously used. (menu, slogan, toolbar, overlay, forum, block titles, etc)

2) Seek approval from someone about limited use-case variation from a Drupal standard.

Anything else?

#35

@mgifford, I consider step (2) to be already finished. We got lots of positive feedback here for moving ahead with this exception to the normal naming convention. The HTML5 and Accessibility teams agree, as do many others who have weighed in.

It looks like the patch needs a re-roll. After that, if one more person reviews it positively it is ready for RTBC.

#36

Ok, I'm going a bit further. If we're going to standardize to the boilerplate, let's standardize to the boilerplate.

EDIT: In #9 above we've @Jacine pulled in the H5BP. If we're going to use their lingo, we might as well use their CSS. Otherwise it's just a bit confusing. We're going to need to do some testing on this with AT, but seems to work with a brief review. Also, I added the invisible class even though it isn't used.

Hopefully this meets the bots requirements.

PS. I also edited the description at the top to fit what was being done in the patch.

AttachmentSizeStatusTest resultOperations
simplify-element-classes-1363112-36.patch31.91 KBIdlePASSED: [[SimpleTest]]: [MySQL] 39,980 pass(es).View details | Re-test

#37

Assigned to:Anonymous» mparker17

Going to test this.

#38

This does not bode well...

mattparker@yavinIV:htdocs/drupal8 (1363112 ✓) % git apply ~/Desktop/simplify-element-classes-1363112-36.patch
/Users/mattparker/Desktop/simplify-element-classes-1363112-36.patch:418: trailing whitespace.
.hidden {
/Users/mattparker/Desktop/simplify-element-classes-1363112-36.patch:438: trailing whitespace.
  position: absolute;
/Users/mattparker/Desktop/simplify-element-classes-1363112-36.patch:457: trailing whitespace.
  width: auto;
/Users/mattparker/Desktop/simplify-element-classes-1363112-36.patch:464: trailing whitespace.
  visibility: hidden;
error: patch failed: core/includes/form.inc:3790
error: core/includes/form.inc: patch does not apply
error: patch failed: core/includes/pager.inc:259
error: core/includes/pager.inc: patch does not apply
error: patch failed: core/includes/theme.inc:1542
error: core/includes/theme.inc: patch does not apply
error: patch failed: core/misc/collapse.js:78
error: core/misc/collapse.js: patch does not apply
error: patch failed: core/modules/block/block.admin.inc:394
error: core/modules/block/block.admin.inc: patch does not apply
error: core/modules/book/book-navigation.tpl.php: No such file or directory
error: core/modules/forum/forum-icon.tpl.php: No such file or directory
error: core/modules/forum/forum-list.tpl.php: No such file or directory
error: patch failed: core/modules/forum/forum.module:1161
error: core/modules/forum/forum.module: patch does not apply
error: patch failed: core/modules/node/lib/Drupal/node/Tests/PageEditTest.php:52
error: core/modules/node/lib/Drupal/node/Tests/PageEditTest.php: patch does not apply
error: patch failed: core/modules/node/node.module:1298
error: core/modules/node/node.module: patch does not apply
error: patch failed: core/modules/overlay/overlay-parent.js:332
error: core/modules/overlay/overlay-parent.js: patch does not apply
error: core/modules/overlay/overlay.tpl.php: No such file or directory
error: core/modules/system/html.tpl.php: No such file or directory
error: patch failed: core/modules/system/lib/Drupal/system/Tests/Form/ElementsLabelsTest.php:65
error: core/modules/system/lib/Drupal/system/Tests/Form/ElementsLabelsTest.php: patch does not apply
error: core/modules/system/page.tpl.php: No such file or directory
error: patch failed: core/modules/system/system.base.css:232
error: core/modules/system/system.base.css: patch does not apply
error: patch failed: core/modules/toolbar/toolbar.module:212
error: core/modules/toolbar/toolbar.module: patch does not apply
error: core/themes/bartik/template.php: No such file or directory
error: patch failed: core/themes/bartik/templates/maintenance-page.tpl.php:25
error: core/themes/bartik/templates/maintenance-page.tpl.php: patch does not apply
error: patch failed: core/themes/bartik/templates/page.tpl.php:101
error: core/themes/bartik/templates/page.tpl.php: patch does not apply
error: core/themes/seven/page.tpl.php: No such file or directory

#39

@mparker: If you look at the date on the patch in #37 you'll see it was last rolled almost 8 months ago. This is a long time in Drupal core development and therefore A LOT has changed, so this patch does not apply cleanly anymore. Care to try and re-roll?

#40

Attached is an updated patch.

Since every hunk in the patch in comment 36 failed to apply, I don't know how to create an interdiff.

AttachmentSizeStatusTest resultOperations
drupal-simplify-element-x-1363112-39.patch52.77 KBIdlePASSED: [[SimpleTest]]: [MySQL] 56,166 pass(es).View details | Re-test

#41

Assigned to:mparker17» Anonymous

Yay, testbot likes it!

Someone else, please review.

We'll probably have to notify the theming team about this change.

#42

Status:needs review» needs work

I read it and it looks good, but now it needs a huge re-roll because of the Twig commit.

#43

Assigned to:Anonymous» mparker17

Will fix.

nobody click here