From 3ad8127e7c6b173284c056f2a1509949030e1ba6 Mon Sep 17 00:00:00 2001 From: Andrew Korpusov Date: Wed, 4 May 2016 17:09:16 +0300 Subject: [PATCH] Tabs feature. Set HTML attributes to `tab-content` container close #131 --- CHANGELOG.md | 2 ++ Tabs.php | 9 ++++++++- tests/TabsTest.php | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a91842d..03b019d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 bootstrap extension Change Log 2.0.7 under development ----------------------- +- Enh #131 Added `tabContentOptions` to set HTML attributes for 'tab-content' container in `Tabs` widget (AndrewKorpusov) - Enh #145: Added the ability to customize the class used to draw dropdowns in `yii\bootstrap\Nav`, `yii\bootstrapButtonDropdown` and `yii\bootstrap\Tab` widgets (PowerGamer1) - 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) @@ -14,6 +15,7 @@ Yii Framework 2 bootstrap extension Change Log - Enh #174: Added `yii\bootstrap\Tabs::renderPanes()` to allow extending the class to manipulate the content between the tabs and the content (thiagotalma) - Bug #196: Remove `role="form"` from `yii\bootstrap\ActiveForm` according to new aria specification (bastardijke) + 2.0.6 March 17, 2016 -------------------- diff --git a/Tabs.php b/Tabs.php index d8f174f..41a7d43 100644 --- a/Tabs.php +++ b/Tabs.php @@ -118,6 +118,12 @@ class Tabs extends Widget * @since 2.0.1 */ public $renderTabContent = true; + /** + * @var array list of HTML attributes for the `tab-content` container. This will always contain the CSS class `tab-content`. + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. + * @since 2.0.7 + */ + public $tabContentOptions = []; /** * @var string name of a class to use for rendering dropdowns withing this widget. Defaults to [[Dropdown]]. * @since 2.0.7 @@ -132,6 +138,7 @@ class Tabs extends Widget { parent::init(); Html::addCssClass($this->options, ['widget' => 'nav', $this->navType]); + Html::addCssClass($this->tabContentOptions, 'tab-content'); } /** @@ -288,6 +295,6 @@ class Tabs extends Widget */ public function renderPanes($panes) { - return $this->renderTabContent ? "\n" . Html::tag('div', implode("\n", $panes), ['class' => 'tab-content']) : ''; + return $this->renderTabContent ? "\n" . Html::tag('div', implode("\n", $panes), $this->tabContentOptions) : ''; } } diff --git a/tests/TabsTest.php b/tests/TabsTest.php index 06fd3b3..e45ccf5 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -138,4 +138,24 @@ class TabsTest extends TestCase $this->assertContains('<' . $checkTag, $out); } + + public function testTabContentOptions() + { + $checkAttribute = "test_attribute"; + $checkValue = "check_attribute"; + + $out = Tabs::widget([ + 'items' => [ + [ + 'label' => 'Page1', 'content'=>'Page1' + ] + ], + 'tabContentOptions' => [ + $checkAttribute => $checkValue + ] + ]); + + $this->assertContains($checkAttribute.'=', $out); + $this->assertContains($checkValue, $out); + } }