Browse Source

Enh #50: Added `dropDownOptions` that is passed to `yii\bootstrap\Nav` dropdown items

tags/2.0.5
Francesc Bautista 10 years ago committed by Alexander Makarov
parent
commit
05253b8fd6
  1. 1
      CHANGELOG.md
  2. 2
      Nav.php
  3. 39
      tests/NavTest.php

1
CHANGELOG.md

@ -10,6 +10,7 @@ Yii Framework 2 bootstrap extension Change Log
- Enh #42: Added support for the glyphicons via `yii\bootstrap\Html::icon()` (klimov-paul)
- Enh #43: Added support for the static form controls via `yii\bootstrap\Html` (klimov-paul)
- Enh #44: Fixed `yii\bootstrap\ButtonDropdown` renders two buttons have same with id if 'split' is enabled (klimov-paul)
- Enh #50: Added `dropDownOptions` that is passed to `yii\bootstrap\Nav` dropdown items (fbau123)
2.0.4 May 10, 2015

2
Nav.php

@ -63,6 +63,7 @@ class Nav extends Widget
* - linkOptions: array, optional, the HTML attributes of the item's link.
* - options: array, optional, the HTML attributes of the item container (LI).
* - active: boolean, optional, whether the item should be on active state or not.
* - dropDownOptions: array, optional, the HTML options that will passed to the [[Dropdown]] widget.
* - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget,
* or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
*
@ -208,6 +209,7 @@ class Nav extends Widget
protected function renderDropdown($items, $parentItem)
{
return Dropdown::widget([
'options' => ArrayHelper::getValue($parentItem, 'dropDownOptions', []),
'items' => $items,
'encodeLabels' => $this->encodeLabels,
'clientOptions' => false,

39
tests/NavTest.php

@ -47,4 +47,43 @@ EXPECTED;
$this->assertEqualsWithoutLE($expected, $out);
}
public function testRenderDropDownWithDropDownOptions()
{
Nav::$counter = 0;
$out = Nav::widget(
[
'items' => [
[
'label' => 'Page1',
'content' => 'Page1',
],
[
'label' => 'Dropdown1',
'dropDownOptions' => ['class' => 'test', 'data-id' => 't1', 'id' => 'test1'],
'items' => [
['label' => 'Page2', 'content' => 'Page2'],
['label' => 'Page3', 'content' => 'Page3'],
]
],
[
'label' => 'Dropdown2',
'visible' => false,
'items' => [
['label' => 'Page4', 'content' => 'Page4'],
['label' => 'Page5', 'content' => 'Page5'],
]
]
]
]
);
$expected = <<<EXPECTED
<ul id="w0" class="nav"><li><a href="#">Page1</a></li>
<li class="dropdown"><a class="dropdown-toggle" href="#" data-toggle="dropdown">Dropdown1 <b class="caret"></b></a><ul id="test1" class="test dropdown-menu" data-id="t1"><li class="dropdown-header">Page2</li>
<li class="dropdown-header">Page3</li></ul></li></ul>
EXPECTED;
$this->assertEqualsWithoutLE($expected, $out);
}
}

Loading…
Cancel
Save