Skip to content

Commit

Permalink
Fix checkbox and radio input rendering. (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 22, 2023
1 parent 0c5272b commit 73f5a33
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/Input/Base/AbstractChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ protected function run(): string
}

$attributes['value'] = is_bool($value) ? (int) $value : $value;
$checkedValue = is_bool($this->checkedValue) ? (int) $this->checkedValue : $this->checkedValue;

$attributes['checked'] = match (empty($this->checkedValue)) {
$attributes['checked'] = match (empty($checkedValue)) {
true => $this->checked,
default => $attributes['value'] === $this->checkedValue,
default => $attributes['value'] === $checkedValue,
};

$inputCheckboxTag = $this->buildInputTag($attributes, $this->type, $this->generateUncheckTag());
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Checkbox/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public function testValue(): void
Assert::equalsWithoutLE(
<<<HTML
<label for="text-6582f2d099e8b">
<input id="text-6582f2d099e8b" type="checkbox" value="1">
<input id="text-6582f2d099e8b" type="checkbox" value="1" checked>
Active
</label>
HTML,
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Color/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Color;
namespace PHPForge\Html\Tests\Input\Color;

use PHPForge\Html\Input\Color;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Date/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Date;
namespace PHPForge\Html\Tests\Input\Date;

use PHPForge\Html\Input\Date;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Datetime/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Datetime;
namespace PHPForge\Html\Tests\Input\Datetime;

use PHPForge\Html\Input\Datetime;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/DatetimeLocal/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\DatetimeLocal;
namespace PHPForge\Html\Tests\Input\DatetimeLocal;

use PHPForge\Html\Input\DatetimeLocal;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Month/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Month;
namespace PHPForge\Html\Tests\Input\Month;

use PHPForge\Html\Input\Month;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Radio/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public function testValue(): void
Assert::equalsWithoutLE(
<<<HTML
<label for="radio-6582f2d099e8b">
<input id="radio-6582f2d099e8b" type="radio" value="1">
<input id="radio-6582f2d099e8b" type="radio" value="1" checked>
Active
</label>
HTML,
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Range/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Range;
namespace PHPForge\Html\Tests\Input\Range;

use PHPForge\Html\Input\Range;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Text/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Text;
namespace PHPForge\Html\Tests\Input\Text;

use PHPForge\Html\Input\Text;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Time/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\Time;
namespace PHPForge\Html\Tests\Input\Time;

use PHPForge\Html\Input\Time;
use PHPForge\Support\Assert;
Expand Down
2 changes: 1 addition & 1 deletion tests/Input/Week/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPForge\Html\Tests\WeeK;
namespace PHPForge\Html\Tests\Input\Week;

use PHPForge\Html\Input\Week;
use PHPForge\Support\Assert;
Expand Down

0 comments on commit 73f5a33

Please sign in to comment.