diff --git a/CHANGELOG.md b/CHANGELOG.md index ac81b8c5..09b895c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Enh #306: Raise `yiisoft/html` version to `^3.13 || ^4.0` (@vjik) - New #305: Add `tabIndex()` method to `Button` widget (@Mister-42) +- Bug #309: Fix `Collapse` re-encoding content already managed by `Toggler` (@vjik) ## 1.1.0 March 06, 2026 diff --git a/src/Collapse.php b/src/Collapse.php index 8e1b69bd..fbdd096b 100644 --- a/src/Collapse.php +++ b/src/Collapse.php @@ -362,14 +362,9 @@ public function render(): string ->addAttributes($this->attributes) ->addContent( "\n", - (new Div()) - ->addAttributes($this->cardBodyAttributes) + Html::div("\n" . $item->getContent() . "\n", $this->cardBodyAttributes) ->addClass(self::CARD, self::CARD_BODY) - ->addContent( - "\n", - $item->getContent(), - "\n", - ), + ->encode(false), "\n", ) ->id($item->getId()); diff --git a/tests/CollapseTest.php b/tests/CollapseTest.php index 59f7c7d2..2497b25c 100644 --- a/tests/CollapseTest.php +++ b/tests/CollapseTest.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use Yiisoft\Bootstrap5\Collapse; use Yiisoft\Bootstrap5\Tests\Support\Assert; @@ -475,4 +476,14 @@ public function testTogglerContainerTag(): void ->render(), ); } + + #[TestWith(['<b>Bold content</b>', true])] + #[TestWith(['Bold content', false])] + public function testTogglerHtmlContent(string $expected, bool $encode): void + { + $toggler = Toggler::for('Bold content', 'collapseExample', encode: $encode)->togglerContent('Toggle'); + $widget = Collapse::widget()->items($toggler); + + $this->assertStringContainsString($expected, $widget->render()); + } }