mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-21 17:20:57 +08:00
Fixes #4146: Added yii\bootstrap\ButtonDropdown::$containerOptions
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
28
tests/unit/extensions/bootstrap/ButtonDropdownTest.php
Normal file
28
tests/unit/extensions/bootstrap/ButtonDropdownTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class TabsTest extends BootstrapTestCase
|
||||
*/
|
||||
public function testIds()
|
||||
{
|
||||
Tabs::$counter = 0;
|
||||
$out = Tabs::widget([
|
||||
'items' => [
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user