ZF-8951: Zend_Navigation View Helper Menu - allow different active classes for active parents
Description
Ideally my output navigation would look something like this:
First Level
Second Level
I would like to display active parents differently from the active leaf nodes. Since I cannot use CSS markup for li.active:has(li.active) I need a different class for the parent nodes. This is a common use-case for me.
I suggest an amend to the Zend/View/Helper/Navigation/Menu.php
258 // create li element for page
259 $liCss = $page->isActive($recursive)
260 ? ' class="active"'
261 : '';
to
258 // create li element for page
259 $liCss = $page->isActive($recursive)
260 ? ' class="active"'
261 : '';
new // show active parent
new if (!$recursive && !$page->isActive(false) && $page->isActive(true)) $liCss = ' class="active-parent"';
This will not change the current behaviour for users using setParentActive. Those not using it will get extra classes which will not affect display (unless they happen to be using that class name).
I think this is a very common use-case, so warrants inclusion in the library, rather than simply using a partial menu template.
I suspect my code could be expressed more elegantly. The option could be added as a new configuration parameter.
Comments
Posted by Kai Uwe (kaiuwe) on 2010-10-21T01:23:46.000+0000
??I need a different class for the parent nodes.?? I think that would be a BC break in HTML and CSS.
My suggestion:
In CSS you can write:
Posted by Frank Brückner (frosch) on 2011-10-10T22:02:53.000+0000
I have found a simple solution. I will write some unit tests and the implementation which includes:
Posted by Frank Brückner (frosch) on 2012-03-21T19:12:15.000+0000
Patch and unit tests added.
Posted by Rob Allen (rob) on 2012-11-07T21:00:11.000+0000
Patch fails to apply
Posted by Rob Allen (rob) on 2012-11-07T21:00:52.000+0000
I'm also a little concerned that adding a class will result in unexpected styling. Maybe name the new class something like zf-nav-parent ?
Posted by Frank Brückner (frosch) on 2012-11-08T17:09:11.000+0000
Or "menu-parent"?
Posted by Frank Brückner (frosch) on 2013-01-11T10:28:09.000+0000
Fixed on trunk (25214) and release-1.12 (25215)
Posted by Frank Brückner (frosch) on 2013-01-11T10:28:35.000+0000
Standard parent class is "menu-parent".