From 05253b8fd6d36ba23292eac65e573d1b1f54b0ec Mon Sep 17 00:00:00 2001 From: Francesc Bautista Date: Mon, 25 May 2015 23:59:26 +0200 Subject: [PATCH] Enh #50: Added `dropDownOptions` that is passed to `yii\bootstrap\Nav` dropdown items --- CHANGELOG.md | 1 + Nav.php | 2 ++ tests/NavTest.php | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc21df..400739c 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/Nav.php b/Nav.php index 0e8e0ac..5be7994 100644 --- a/Nav.php +++ b/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, diff --git a/tests/NavTest.php b/tests/NavTest.php index 3fad720..3510af4 100644 --- a/tests/NavTest.php +++ b/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 = <<
  • Page1
  • + +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } }