Problem/Motivation

The styling of the menu is not inline with our CSS coding standards.

See: #1995272: [Meta] Refactor module CSS files inline with our CSS standards

Proposed resolution

Bring them inline with our standards.

Before:

.expanded
.collapsed
.leaf
.active-trail

After:

.menu-item--expanded
.menu-item--collapsed
.menu-item--leaf
.menu-item--active-trail

Remaining tasks

Review the current CSS — What to look for when reviewing CSS

User interface changes

None

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 HTML/CSS

Comments

joelpittet’s picture

Status: Needs review » Needs work

You know what would be really helpful here... .menu-item--leaf class. But that may be out of scope of this issue. Is there another issue to rename this class @mortendk?

I double checked, there is no other uses of the 'leaf' class than li elements in core but it is very generic a class name needs some BEM!

mortendk’s picture

i dont think we should rename anything here . just clean the csslint.
yes im a bit anti scope creep, but hey gets the job done

lewisnyman’s picture

Title: menus-and-lists.css css lint fix » Rewrite the menu CSS components inline with our CSS standards
Component: Seven theme » menu system
Category: Bug report » Task
Issue summary: View changes
Parent issue: #1190252: [573] Use csslint as a weapon to beat the crappy CSS out of Drupal core » #1995272: [Meta] Refactor module CSS files inline with our CSS standards

This is an example of an issue were we need to this about the entire component, because if we weaken the selector in Seven we introduce potential for regressions because the module CSS is now stronger, if we change the module CSS we should also look at Bartik. We can use #1995272: [Meta] Refactor module CSS files inline with our CSS standards to add issues that affect all themes, so we can tackle it everywhere in one go.

joelpittet’s picture

Issue summary: View changes
joelpittet’s picture

Issue summary: View changes
joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new13.61 KB

Ok hopefully this is on the right track?

lewisnyman’s picture

Status: Needs review » Needs work

This is looking really good :) mmm tidier CSS

  1. +++ b/core/modules/book/src/BookManager.php
    @@ -503,28 +503,22 @@ public function bookTreeOutput(array $tree) {
    -      $class = array();
    -      if ($i == 0) {
    -        $class[] = 'first';
    -      }
    -      if ($i == $num_items - 1) {
    -        $class[] = 'last';
    -      }
    

    Just making sure this is an intentional removal? I don't see how it fits within the scope of this issue.

  2. +++ b/core/modules/book/src/BookManager.php
    @@ -503,28 +503,22 @@ public function bookTreeOutput(array $tree) {
    -        $class[] = 'leaf';
    +        $class[] = 'menu-item--leaf';
    

    Is the menu-item class supposed to be replacing the leaf class or extending it?

lewisnyman’s picture

Issue tags: +Needs screenshots

We are going to need some thorough visual regression testing

joelpittet’s picture

OH YES first and last removal was intentional.
RE:
1) It's not being used in CSS, already removed in menu build.
2) Extending. It's a type of menu-item (with no children)

mortendk’s picture

+1 on this ... even that my heart burns over the epic scope creep ;)

+++ b/core/themes/seven/css/components/menus-and-lists.css
@@ -10,21 +10,20 @@
-li.leaf,

I fully support killing of the leaf class its an edge case -its terrible in so many ways.
Do we even have a list of all the places we have menus.
Also do we need em in seven, classy, stark, bartik ?

joelpittet’s picture

Oh yeah should have mentioned. li.leaf's use was already covered by .menu li's CSS. Which is now covered by .menu-item... and that was it's only use in core. If there is an easy way to add it back through contrib (either extending MenuLinkTree::build() or doing it in the template...) and we can document that process then I think it would be safe to remove completely. It's an edge case indeed(when you need to style childless menu items different from ones with children, which you can do by targeting .menu-link--expanded/.menu-link--collapsed and excluding the styles on the children without it).

I've checked all of core for leaf, there was just that class and the class addition which is now .menu-item--leaf.

mortendk’s picture

i might be biased but i have a hard time to see .leaf come under our basic rule or "building for the 80%" usecase.
Its one of these old Drupal4.7 things that are still sticking around, cause that was how we used to do it.

Lets try not to carry on all the bagage from ye old days :)

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new1.34 KB
new31.64 KB

Fixed a couple of bugs in the toolbar and reviewed the changes a bit closer. Seems to be working out pretty well.

joelpittet’s picture

@mortendk hook me up with documentation on how we can achieve the .menu-item--leaf class without core and I'll gladly remove it in this patch... deal? Dare ya:P

mortendk’s picture

@joel deal - point me to menu that have that leaf & ill make it hotpink for you :)

mortendk’s picture

Issue summary: View changes
StatusFileSize
new4.55 KB
new180.65 KB
new181.39 KB

omg im to tired wrong patch

joelpittet’s picture

StatusFileSize
new13.64 KB

Turkey! :P Re-uploading 13

joelpittet’s picture

StatusFileSize
new19.34 KB

@mortendk

lewisnyman’s picture

I think people are able to do something like .menu-item .menu-item .menu-item to move down the structure of a menu, I don't think .leaf covers 80%

joelpittet’s picture

@LewisNyman yes and yes re #19 just doing some trading so we don't remove a "feature" without giving someone a fallback plan. .menu-item-leaf = .menu-item:not(.menu-item-collapsed):not(.menu-item-expanded)

OR the reverse just make the default .menu-item and override it on the other two which is the majority of cases.

Trying to get @mortendk to write the template example for determining and adding that class;) For good practice:P

mortendk’s picture

so your trying to get me to write the documentation so i can get .leaf out of core
... that pretty clever ;)

mortendk’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -csslint, -Novice, -Needs screenshots
StatusFileSize
new190.42 KB
new306.99 KB
new350.19 KB
new370 KB
new346.14 KB
new313.17 KB

Tested!
Menu:

menu user

toolbar

toolbar stark with *.theme.css

toolbar stark with no theme css !

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

We need a change record for this.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
mortendk’s picture

added change notice: https://www.drupal.org/node/2427587 [#2427587]

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +JavaScript
    /**
     * On page load, open the active menu item.
     *
     * Marks the trail of the active link in the menu back to the root of the
     * menu with .active-trail.
     *
     * @param {jQuery} $menu
     *   The root of the menu.
     */
    function openActiveItem($menu) {
      var pathItem = $menu.find('a[href="' + location.pathname + '"]');
      if (pathItem.length && !activeItem) {
        activeItem = location.pathname;
      }
      if (activeItem) {
        var $activeItem = $menu.find('a[href="' + activeItem + '"]').addClass('active');
        var $activeTrail = $activeItem.parentsUntil('.root', 'li').addClass('active-trail');
        toggleList($activeTrail, true);
      }
    }

This looks wrong now.

.expanded .locale-translation-update__wrapper {
  background: transparent url(../../../misc/menu-expanded.png) left .6em no-repeat;
}

This looks like this change might break it - depends if this is for an expanded details or menu... not sure.

davidhernandez’s picture

I merged the change record for this issue with the one from #2425691: Remove .leaf/.menu-item--leaf from menu CSS components, per Alex's suggestion.

mortendk’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes
new11.59 KB

@alex your spot on the .addClass('active'); should be named to menu-item--active
the patch also needed some adjust ment after we removed leaf :)

davidhernandez’s picture

Status: Needs review » Needs work

Morten, your patch file is empty.

mortendk’s picture

StatusFileSize
new15.2 KB

and again ;)

mortendk’s picture

StatusFileSize
new15.2 KB
+++ b/core/modules/book/src/BookManager.php
@@ -503,27 +503,21 @@ public function bookTreeOutput(array $tree) {
+        $data['link']['localized_options']['attributes']['class'][] = 'menu-teim--active-trail';

ups

davidhernandez’s picture

Status: Needs work » Needs review

The last submitted patch, 30: rewrite_the_menu_css-2422363-30.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 31: rewrite_the_menu_css-2422363-31.patch, failed testing.

davidhernandez’s picture

Status: Needs work » Needs review
StatusFileSize
new15.99 KB
new812 bytes

Looks like changes to Seven's menus-and-lists from #17 when missing. I'm not seeing a comment that says it was intentional.

No idea why that file copy test is failing. I ran it locally and it passed after I made the Seven change. If that is the cause, good grief.

mortendk’s picture

Status: Needs review » Reviewed & tested by the community

*shakes fist at testbot* look good to me

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

CSS is not frozen in beta. Committed 806def4 and pushed to 8.0.x. Thanks!

  • alexpott committed 806def4 on 8.0.x
    Issue #2422363 by mortendk, joelpittet, davidhernandez: Rewrite the menu...
idebr’s picture

+++ b/core/themes/bartik/css/components/primary-menu.css
@@ -97,11 +97,11 @@ body:not(:target) .region-primary-menu .menu-toggle-target-show:target ~ .menu-t
-body:not(:target) .region-primary-menu .menu-toggle-target-show:target ~ .menu li {
+body:not(:target) .region-primary-menu .menu-toggle-target-show:target ~ .menu-item {

This selector change broke the toggle for the primary navigation in Bartik. I have opened a followup at #2430735: Primary navigation toggle broken in Bartik to fix this.

Status: Fixed » Closed (fixed)

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