diff --git a/CHANGELOG.md b/CHANGELOG.md index fd7214c..1f4fd0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Yii Framework 2 bootstrap extension Change Log - Enh #2546: Added `visible` option to `yii\bootstrap\ButtonGroup::$buttons` (samdark, lukBarros) - Enh #7633: Added `ActionColumn::$buttonOptions` for defining HTML options to be added to the default buttons (cebe) - Enh: Added `Nav::$dropDownCaret` to allow customization of the dropdown caret symbol (cebe) +- Enh: Added support for using external URLs for `Tabs`. (dynasource, qiangxue) 2.0.3 March 01, 2015 diff --git a/Tabs.php b/Tabs.php index 0f8d6c9..6e244c6 100644 --- a/Tabs.php +++ b/Tabs.php @@ -31,6 +31,10 @@ use yii\helpers\Html; * 'options' => ['id' => 'myveryownID'], * ], * [ + * 'label' => 'Example', + * 'url' => 'http://www.example.com', + * ], + * [ * 'label' => 'Dropdown', * 'items' => [ * [ @@ -63,6 +67,8 @@ class Tabs extends Widget * - headerOptions: array, optional, the HTML attributes of the tab header. * - linkOptions: array, optional, the HTML attributes of the tab header link tags. * - content: string, optional, the content (HTML) of the tab pane. + * - url: string, optional, an external URL. When this is specified, clicking on this tab will bring + * the browser to this URL. This option is available since version 2.0.4. * - options: array, optional, the HTML attributes of the tab pane container. * - active: boolean, optional, whether the item tab header and pane should be visible or not. * - items: array, optional, can be used instead of `content` to specify a dropdown items @@ -171,8 +177,14 @@ class Tabs extends Widget Html::addCssClass($options, 'active'); Html::addCssClass($headerOptions, 'active'); } - $linkOptions['data-toggle'] = 'tab'; - $header = Html::a($label, '#' . $options['id'], $linkOptions); + + if (isset($item['url'])) { + $header = Html::a($label, $item['url'], $linkOptions); + } else { + $linkOptions['data-toggle'] = 'tab'; + $header = Html::a($label, '#' . $options['id'], $linkOptions); + } + if ($this->renderTabContent) { $panes[] = Html::tag('div', isset($item['content']) ? $item['content'] : '', $options); } diff --git a/tests/TabsTest.php b/tests/TabsTest.php index 18e39c7..4f61098 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\bootstrap; use yii\bootstrap\Tabs; +use yii\helpers\Html; /** * Tests for Tabs widget @@ -36,7 +37,10 @@ class TabsTest extends TestCase ['label' => 'Page4', 'content' => 'Page4'], ['label' => 'Page5', 'content' => 'Page5'], ] - ] + ], + [ + 'label' => $extAnchor = 'External link', 'url' => $extUrl = ['//other/route'], + ], ] ]); @@ -65,6 +69,7 @@ class TabsTest extends TestCase "id=\"$page3\"", "id=\"$page4\"", "id=\"$page5\"", + Html::a($extAnchor,$extUrl), ]; foreach ($shouldContain as $string) {