From 773e601d6fc46acc0cedb8f1fcce8a2a3f804a6f Mon Sep 17 00:00:00 2001 From: Simon Karlen Date: Wed, 4 Aug 2021 08:51:53 +0200 Subject: [PATCH] fixed toggle button group rendering --- src/ToggleButtonGroup.php | 15 +++++++-------- tests/ToggleButtonGroupTest.php | 16 ++++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ToggleButtonGroup.php b/src/ToggleButtonGroup.php index 14b86c7..4f79fe2 100644 --- a/src/ToggleButtonGroup.php +++ b/src/ToggleButtonGroup.php @@ -53,7 +53,7 @@ class ToggleButtonGroup extends InputWidget * @see Html::radio() */ public $labelOptions = [ - 'class' => ['btn', 'btn-secondary'], + 'class' => ['btn', 'btn-outline-secondary'], ]; /** * @var bool whether the items labels should be HTML-encoded. @@ -115,21 +115,20 @@ class ToggleButtonGroup extends InputWidget { unset($index); $labelOptions = $this->labelOptions; - $labelOptions['wrapInput'] = true; + $labelOptions['wrapInput'] = false; Html::addCssClass($labelOptions, ['widget' => 'btn']); - if ($checked) { - Html::addCssClass($labelOptions, ['activate' => 'active']); - } $type = $this->type; if ($this->encodeLabels) { $label = Html::encode($label); } - - return Html::$type($name, $checked, [ + $options = [ 'label' => $label, 'labelOptions' => $labelOptions, 'autocomplete' => 'off', 'value' => $value, - ]); + ]; + Html::addCssClass($options, ['widget' => 'btn-check']); + + return Html::$type($name, $checked, $options); } } diff --git a/tests/ToggleButtonGroupTest.php b/tests/ToggleButtonGroupTest.php index ee4718a..f603cf2 100644 --- a/tests/ToggleButtonGroupTest.php +++ b/tests/ToggleButtonGroupTest.php @@ -25,8 +25,10 @@ class ToggleButtonGroupTest extends TestCase ]); $expectedHtml = <<
-
+
+ + +
HTML; $this->assertEqualsWithoutLE($expectedHtml, $html); } @@ -46,7 +48,7 @@ HTML; ], ]); - $this->assertContains('', $html); + $this->assertContains('', $html); } public function testRadio() @@ -63,8 +65,10 @@ HTML; ]); $expectedHtml = <<
-
+
+ + +
HTML; $this->assertEqualsWithoutLE($expectedHtml, $html); } @@ -84,7 +88,7 @@ HTML; ], ]); - $this->assertContains('', $html); + $this->assertContains('', $html); } }