Browse Source

Merge pull request #142 from Okeanos/master

Allow URLs to be used as Dropdown items in Tab Widgets #113
tags/2.0.7
Carsten Brandt 8 years ago committed by GitHub
parent
commit
a7a9282477
  1. 1
      CHANGELOG.md
  2. 11
      Tabs.php
  3. 16
      tests/TabsTest.php

1
CHANGELOG.md

@ -7,6 +7,7 @@ Yii Framework 2 bootstrap extension Change Log
- Bug #126: `yii\bootstrap\ToggleButtonGroup` was unable to work without model (makroxyz) - Bug #126: `yii\bootstrap\ToggleButtonGroup` was unable to work without model (makroxyz)
- Bug #130: Fixed `yii\bootstrap\Collapse` to use pure numerical value on `content` property (meysampg) - Bug #130: Fixed `yii\bootstrap\Collapse` to use pure numerical value on `content` property (meysampg)
- Bug #137: Remove `role="navbar"` from `yii\bootstrap\NavBar` according to new aria specification (tino415) - Bug #137: Remove `role="navbar"` from `yii\bootstrap\NavBar` according to new aria specification (tino415)
- Enh #113: Allow URLs instead of content for Tab Widget Dropdown items (Okeanos)
2.0.6 March 17, 2016 2.0.6 March 17, 2016
-------------------- --------------------

11
Tabs.php

@ -44,6 +44,10 @@ use yii\helpers\ArrayHelper;
* 'label' => 'DropdownB', * 'label' => 'DropdownB',
* 'content' => 'DropdownB, Anim pariatur cliche...', * 'content' => 'DropdownB, Anim pariatur cliche...',
* ], * ],
* [
* 'label' => 'External Link',
* 'url' => 'http://www.example.com',
* ],
* ], * ],
* ], * ],
* ], * ],
@ -240,8 +244,11 @@ class Tabs extends Widget
if (isset($item['visible']) && !$item['visible']) { if (isset($item['visible']) && !$item['visible']) {
continue; continue;
} }
if (!array_key_exists('content', $item)) { if (!(array_key_exists('content', $item) xor array_key_exists('url', $item))) {
throw new InvalidConfigException("The 'content' option is required."); throw new InvalidConfigException("Either the 'content' or the 'url' option is required, but only one can be set.");
}
if (array_key_exists('url', $item)) {
continue;
} }
$content = ArrayHelper::remove($item, 'content'); $content = ArrayHelper::remove($item, 'content');

16
tests/TabsTest.php

@ -39,7 +39,13 @@ class TabsTest extends TestCase
] ]
], ],
[ [
'label' => $extAnchor = 'External link', 'url' => $extUrl = ['//other/route'], 'label' => $extAnchor1 = 'External link', 'url' => $extUrl1 = ['//other/route'],
],
[
'label' => 'Dropdown3',
'items' => [
['label' => $extAnchor2 = 'External Dropdown Link', 'url' => $extUrl2 = ['//other/dropdown/route']],
]
], ],
] ]
]); ]);
@ -63,13 +69,16 @@ class TabsTest extends TestCase
"#$page4", // Page4 "#$page4", // Page4
"#$page5", // Page5 "#$page5", // Page5
'w3', // Dropdown3
// containers // containers
"id=\"$page1\"", "id=\"$page1\"",
"id=\"$page2\"", "id=\"$page2\"",
"id=\"$page3\"", "id=\"$page3\"",
"id=\"$page4\"", "id=\"$page4\"",
"id=\"$page5\"", "id=\"$page5\"",
Html::a($extAnchor,$extUrl), Html::a($extAnchor1,$extUrl1),
Html::a($extAnchor2,$extUrl2, ['tabindex' => -1]),
]; ];
foreach ($shouldContain as $string) { foreach ($shouldContain as $string) {
@ -96,6 +105,8 @@ class TabsTest extends TestCase
['label' => 'Page2', 'content' => 'Page2'], ['label' => 'Page2', 'content' => 'Page2'],
['label' => 'InvisibleItem', 'content' => 'Invisible Item Content', 'visible' => false], ['label' => 'InvisibleItem', 'content' => 'Invisible Item Content', 'visible' => false],
['label' => 'Page3', 'content' => 'Page3'], ['label' => 'Page3', 'content' => 'Page3'],
['label' => 'External Link', 'url' => ['//other/dropdown/route']],
['label' => 'Invisible External Link', 'url' => ['//other/dropdown/route'], 'visible' => false],
] ]
], ],
] ]
@ -105,6 +116,7 @@ class TabsTest extends TestCase
$this->assertNotContains('Invisible Page Content', $html); $this->assertNotContains('Invisible Page Content', $html);
$this->assertNotContains('InvisibleItem', $html); $this->assertNotContains('InvisibleItem', $html);
$this->assertNotContains('Invisible Item Content', $html); $this->assertNotContains('Invisible Item Content', $html);
$this->assertNotContains('Invisible External Link', $html);
} }
public function testItem() public function testItem()

Loading…
Cancel
Save