Commit c2ef433e by Alexander Makarov

Fixes #4146: Added `yii\bootstrap\ButtonDropdown::$containerOptions`

parent e6450be6
......@@ -7,6 +7,7 @@
namespace yii\bootstrap;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
......@@ -38,6 +39,15 @@ class ButtonDropdown extends Widget
*/
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');
}
......
......@@ -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)
......
......@@ -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)
......
<?php
namespace yiiunit\extensions\bootstrap;
use yii\bootstrap\ButtonDropdown;
class ButtonDropdownTest extends BootstrapTestCase
{
public function testContainerOptions()
{
$containerClass = "dropup";
ButtonDropdown::$counter = 0;
$out = ButtonDropdown::widget([
'containerOptions' => [
'class' => $containerClass,
],
'label' => 'Action',
'dropdown' => [
'items' => [
['label' => 'DropdownA', 'url' => '/'],
['label' => 'DropdownB', 'url' => '#'],
],
],
]);
$this->assertContains("$containerClass btn-group", $out);
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ class TabsTest extends BootstrapTestCase
*/
public function testIds()
{
Tabs::$counter = 0;
$out = Tabs::widget([
'items' => [
[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment