diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bde18a..532fe49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 bootstrap extension Change Log 2.0.7 under development ----------------------- +- Bug #157: Active status of multilevel submenu items of the `yii\bootstrap\Nav` class is determined correctly now (PowerGamer1) - Enh #64: Added simplified syntax for specifying `Collapse` widget `$items` (Faryshta, cebe) - Enh #131 Added `tabContentOptions` to set HTML attributes for 'tab-content' container in `Tabs` widget (AndrewKorpusov) - Enh #145: Added the ability to customize the class used to draw dropdowns in `yii\bootstrap\Nav`, `yii\bootstrapButtonDropdown` and `yii\bootstrap\Tab` widgets (PowerGamer1) diff --git a/Nav.php b/Nav.php index 947f604..eb41a86 100644 --- a/Nav.php +++ b/Nav.php @@ -106,7 +106,7 @@ class Nav extends Widget */ public $dropDownCaret; /** - * @var string name of a class to use for rendering dropdowns withing this widget. Defaults to [[Dropdown]]. + * @var string name of a class to use for rendering dropdowns within this widget. Defaults to [[Dropdown]]. * @since 2.0.7 */ public $dropdownClass = 'yii\bootstrap\Dropdown'; @@ -234,12 +234,24 @@ class Nav extends Widget protected function isChildActive($items, &$active) { foreach ($items as $i => $child) { + if (is_array($child) && !ArrayHelper::getValue($child, 'visible', true)) { + continue; + } if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) { Html::addCssClass($items[$i]['options'], 'active'); if ($this->activateParents) { $active = true; } } + $childItems = ArrayHelper::getValue($child, 'items'); + if (is_array($childItems)) { + $activeParent = false; + $items[$i]['items'] = $this->isChildActive($childItems, $activeParent); + if ($activeParent) { + Html::addCssClass($items[$i]['options'], 'active'); + $active = true; + } + } } return $items; } diff --git a/tests/NavTest.php b/tests/NavTest.php index c6df667..d620ad3 100644 --- a/tests/NavTest.php +++ b/tests/NavTest.php @@ -272,6 +272,37 @@ EXPECTED; } /** + * @see https://github.com/yiisoft/yii2-bootstrap/issues/96 + * @see https://github.com/yiisoft/yii2-bootstrap/issues/157 + */ + public function testDeepActivateParents() + { + Nav::$counter = 0; + $out = Nav::widget([ + 'activateParents' => true, + 'items' => [ + [ + 'label' => 'Dropdown', + 'items' => [ + [ + 'label' => 'Sub-dropdown', + 'items' => [ + ['label' => 'Page', 'content' => 'Page', 'active' => true], + ], + ], + ], + ], + ], + ]); + + $expected = << +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } + + /** * Mocks controller action with parameters * * @param string $controllerId