Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi
I've been using Nice Menus since Drupal 6. I'm now working on my first Drupal 8 site and I've noticed that the Nice Menu module in Drupal 8 doesn't add the class 'active-trail' (or any other class) to the parent of an active item. We need that class added so we can style the parent of an active page within a dropdown menu.
Any ideas?
Thanks
Frank
Comment | File | Size | Author |
---|---|---|---|
#7 | no_active_trail-2846707-7.patch | 3.22 KB | ytsurk |
#6 | no_active_trail-2846707-6.patch | 573 bytes | ytsurk |
#5 | no_active_trail-2846707-5.patch | 500 bytes | ytsurk |
Comments
Comment #2
xiukun.zhou CreditAttribution: xiukun.zhou commentedHI. drupal8 have "menuparent" class
Comment #3
caspervoogt CreditAttribution: caspervoogt at Plethora commentedI don't actually see an 'active' class being added to any menu items at all.
I do see a 'menuparent' being applied to items that have sub-items but these are also getting the 'menu-item--expanded' class even when they are not expanded.
Comment #4
caspervoogt CreditAttribution: caspervoogt at Plethora commentedSlight correction. An "is-active" class gets added to my front page menu item link. No other menu items get an "is-active" class. My theme has nothing overriding anything remotely menu-related. I have tried it with Bartik as well - same thing.
Comment #5
ytsurkI can confirm the issue.
menu-parent
means that the menuitem has childrens ... not that it's active.is-active
is only set on the anchor tag.Looking at the core's menu block i made a patch to get the active trail. Now the class .menu-item--active-trail is added like in other menus.
Is there a reason why nice_menus uses the
toolbar.menu_tree
service and not themenu.link_tree
service like cores' does ? This could be adapted as well.Comment #6
ytsurkHere another simplified approach, with every item expanded (like it was before).
Comment #7
ytsurkHere the final patch also respecting caching !
Comment #8
ytsurkComment #9
Huelfe CreditAttribution: Huelfe commentedI just tried the patch from #7 but there is a caching problem. When I rebuild the cache and visit a page which is linked in the menu, then the visited menu item always has the class "menu-item--active-trail". When I click on other menu items, the class still belongs to the menu item, which was visited first after cache rebuild.
Comment #10
ytsurkI cannot reproduce this behavior. What cache are you using ?
I have enabled page_cache and dynamic_page_cache, running drupal 8.4.3 and also below ..
.menu-item--active-trail
is appended to the active menu entry (li tag) and every parent of it..is-active
is appended only to the active menu entry (a tag).Comment #12
xiukun.zhou CreditAttribution: xiukun.zhou commentedThanks ytsurk
i have added a default config.
Comment #13
xiukun.zhou CreditAttribution: xiukun.zhou commentedComment #15
dfletcher CreditAttribution: dfletcher commentedThanks patch in #7 worked great for me (from 8.x-1.0-beta2).