diff --git a/extensions/bootstrap/ButtonDropdown.php b/extensions/bootstrap/ButtonDropdown.php index 5fc6f628c8..3563d71c3a 100644 --- a/extensions/bootstrap/ButtonDropdown.php +++ b/extensions/bootstrap/ButtonDropdown.php @@ -7,6 +7,7 @@ namespace yii\bootstrap; +use yii\helpers\ArrayHelper; use yii\helpers\Html; /** @@ -37,6 +38,15 @@ class ButtonDropdown extends Widget * @var string the button label */ public $label = 'Button'; + /** + * @var array the HTML attributes for the container tag. The following special options are recognized: + * + * - tag: string, defaults to "div", the name of the container tag. + * + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. + * @since 2.0.1 + */ + public $containerOptions = []; /** * @var array the HTML attributes of the button. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. @@ -65,10 +75,14 @@ class ButtonDropdown extends Widget */ public function run() { - echo Html::beginTag('div', ['class' => 'btn-group']); + Html::addCssClass($this->containerOptions, 'btn-group'); + $options = $this->containerOptions; + $tag = ArrayHelper::remove($options, 'tag', 'div'); + + echo Html::beginTag($tag, $this->containerOptions); echo "\n" . $this->renderButton(); echo "\n" . $this->renderDropdown(); - echo "\n" . Html::endTag('div'); + echo "\n" . Html::endTag($tag); $this->registerPlugin('button'); } diff --git a/extensions/bootstrap/CHANGELOG.md b/extensions/bootstrap/CHANGELOG.md index a7f48ccdce..b821620bb5 100644 --- a/extensions/bootstrap/CHANGELOG.md +++ b/extensions/bootstrap/CHANGELOG.md @@ -6,6 +6,7 @@ Yii Framework 2 bootstrap extension Change Log - Bug #5570: `yii\bootstrap\Tabs` would throw an exception if `content` is not set for one of its `items` (RomeroMsk) - Bug #6150: `yii\bootstrap\Tabs` dropdown IDs were generated incorrectly (samdark) +- Enh #4146: Added `yii\bootstrap\ButtonDropdown::$containerOptions` (samdark) - Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark) - Enh #4450: Added `yii\bootstrap\Nav::renderDropdown()` (qiangxue) - Enh #5735: Added `yii\bootstrap\Tabs::renderTabContent` to support manually rendering tab contents (RomeroMsk) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e113d70d29..3b481f5711 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -40,6 +40,7 @@ Yii Framework 2 Change Log - Bug: Gii console command help information does not contain global options (qiangxue) - Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark) - Bug: `yii\web\AssetManager` should not publish disabled asset bundles (qiangxue) +- Enh #4146: Added `yii\bootstrap\ButtonDropdown::$containerOptions` (samdark) - Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark) - Enh #4263: Added migration and SQL schema files for `yii\log\DbTarget` (samdark) - Enh #4450: Added `yii\bootstrap\Nav::renderDropdown()` (qiangxue) diff --git a/tests/unit/extensions/bootstrap/ButtonDropdownTest.php b/tests/unit/extensions/bootstrap/ButtonDropdownTest.php new file mode 100644 index 0000000000..d73c98a6a8 --- /dev/null +++ b/tests/unit/extensions/bootstrap/ButtonDropdownTest.php @@ -0,0 +1,28 @@ + [ + 'class' => $containerClass, + ], + 'label' => 'Action', + 'dropdown' => [ + 'items' => [ + ['label' => 'DropdownA', 'url' => '/'], + ['label' => 'DropdownB', 'url' => '#'], + ], + ], + ]); + + $this->assertContains("$containerClass btn-group", $out); + } +} \ No newline at end of file diff --git a/tests/unit/extensions/bootstrap/TabsTest.php b/tests/unit/extensions/bootstrap/TabsTest.php index 05c499756e..921b9a9215 100644 --- a/tests/unit/extensions/bootstrap/TabsTest.php +++ b/tests/unit/extensions/bootstrap/TabsTest.php @@ -15,6 +15,7 @@ class TabsTest extends BootstrapTestCase */ public function testIds() { + Tabs::$counter = 0; $out = Tabs::widget([ 'items' => [ [