diff --git a/Nav.php b/Nav.php index a003d41..3a93c31 100644 --- a/Nav.php +++ b/Nav.php @@ -177,7 +177,7 @@ class Nav extends Widget $active = $this->isItemActive($item); } - if ($items !== null) { + if (!empty($items)) { $linkOptions['data-toggle'] = 'dropdown'; Html::addCssClass($options, ['widget' => 'dropdown']); Html::addCssClass($linkOptions, ['widget' => 'dropdown-toggle']); @@ -192,6 +192,10 @@ class Nav extends Widget } } + if (empty($items)) { + $items = ''; + } + if ($this->activateItems && $active) { Html::addCssClass($options, 'active'); } diff --git a/tests/NavTest.php b/tests/NavTest.php index 3510af4..7044e22 100644 --- a/tests/NavTest.php +++ b/tests/NavTest.php @@ -85,5 +85,38 @@ EXPECTED; EXPECTED; $this->assertEqualsWithoutLE($expected, $out); - } + } + + public function testEmptyItems() + { + Nav::$counter = 0; + $out = Nav::widget([ + 'items' => [ + [ + 'label' => 'Page1', + 'items' => null, + ], + [ + 'label' => 'Dropdown1', + 'items' => [ + ['label' => 'Page2', 'content' => 'Page2'], + ['label' => 'Page3', 'content' => 'Page3'], + ], + ], + [ + 'label' => 'Page4', + 'items' => [], + ], + ], + ]); + + $expected = <<
  • Page1
  • + +
  • Page4
  • +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } }