Skip to content

Commit 339f384

Browse files
author
simialbi
committed
fixed #88
1 parent fe2198e commit 339f384

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Yii Framework 2 bootstrap5 extension Change Log
44
2.0.51 under development
55
------------------------
66

7+
- Bug #88: Fix ButtonDropdown JS error (stevekr, simialbi)
8+
79
2.0.50 April 10, 2025
810
---------------------
911

src/Button.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class Button extends Widget
5050
public function init(): void
5151
{
5252
parent::init();
53-
$this->clientOptions = [];
5453
Html::addCssClass($this->options, [
5554
'widget' => 'btn',
5655
]);

src/ButtonDropdown.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ class ButtonDropdown extends Widget
104104
*/
105105
public $renderContainer = true;
106106

107-
107+
/**
108+
* {@inheritDoc}
109+
*/
108110
public function init(): void
109111
{
110112
parent::init();
@@ -204,6 +206,7 @@ protected function renderButton(): string
204206
'tagName' => $this->tagName,
205207
'label' => $label,
206208
'options' => $buttonOptions,
209+
'clientOptions' => false,
207210
'encodeLabel' => false,
208211
'view' => $this->getView(),
209212
]) . "\n" . $splitButton;

tests/ButtonDropdownTest.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class ButtonDropdownTest extends TestCase
1313
{
14-
public function testContainerOptions()
14+
public function testContainerOptions(): void
1515
{
1616
$containerClass = 'testClass';
1717

@@ -39,7 +39,7 @@ public function testContainerOptions()
3939
$this->assertStringContainsString("$containerClass dropup btn-group", $out);
4040
}
4141

42-
public function testDirection()
42+
public function testDirection(): void
4343
{
4444
ButtonDropdown::$counter = 0;
4545
$out = ButtonDropdown::widget([
@@ -69,7 +69,7 @@ public function testDirection()
6969
$this->assertEqualsWithoutLE($expected, $out);
7070
}
7171

72-
public function testSplit()
72+
public function testSplit(): void
7373
{
7474
ButtonDropdown::$counter = 0;
7575
$out = ButtonDropdown::widget([
@@ -99,4 +99,34 @@ public function testSplit()
9999

100100
$this->assertEqualsWithoutLE($expected, $out);
101101
}
102+
103+
/**
104+
* @see https://github.com/yiisoft/yii2-bootstrap5/pull/88 fix
105+
*/
106+
public function testGeneratedJS(): void
107+
{
108+
ButtonDropdown::$counter = 0;
109+
$out = ButtonDropdown::widget([
110+
'direction' => ButtonDropdown::DIRECTION_DOWN,
111+
'label' => 'Action',
112+
'dropdown' => [
113+
'items' => [
114+
[
115+
'label' => 'DropdownA',
116+
'url' => '/',
117+
],
118+
[
119+
'label' => 'DropdownB',
120+
'url' => '#',
121+
],
122+
],
123+
],
124+
]);
125+
126+
$js = array_shift(\Yii::$app->view->js);
127+
128+
$this->assertIsArray($js);
129+
$this->assertNotContains('(new bootstrap.Button(\'#w0-button\', {}));', $js);
130+
$this->assertContains('(new bootstrap.Dropdown(\'#w0-button\', {}));', $js);
131+
}
102132
}

0 commit comments

Comments
 (0)