diff --git a/src/Forms/Select.php b/src/Forms/Select.php
index a3eb455..14f48d6 100644
--- a/src/Forms/Select.php
+++ b/src/Forms/Select.php
@@ -125,6 +125,7 @@ private function selectDropdown(): Element
{
$elements = [];
foreach ($this->options as $value => $content) {
+ $value = strval($value);
$option = Element::option($content)->props('value ' . $value);
if ($this->isSelected($value)) {
$option = $option->prop('selected selected');
@@ -150,6 +151,7 @@ private function selectOther(): Element
$type = 'checkbox';
}
foreach ($this->options as $value => $content) {
+ $value = strval($value);
$id = $this->name . '-' . $value;
$label = Element::label($content)->props('for ' . $id);
$input = Element::input()->omitEndTag()->props(
diff --git a/tests/Forms/SelectTest.php b/tests/Forms/SelectTest.php
index c478a1e..ea22a14 100644
--- a/tests/Forms/SelectTest.php
+++ b/tests/Forms/SelectTest.php
@@ -118,4 +118,25 @@ public function is_expected_base(): void // phpcs:ignore
$this->assertSame($expected, $result);
}
+
+ /**
+ * @test
+ */
+ public function error_is_selected_value_always_string(): void // phpcs:ignore
+ {
+ $expected = <<
+ html;
+
+ // Even with strict types, number-based keys become integers
+ $result = (string) Select::create(
+ 'Select your option',
+ 'select',
+ [
+ '0' => 'display'
+ ]
+ );
+
+ $this->assertSame($expected, $result);
+ }
}