diff --git a/src/Forms/Select.php b/src/Forms/Select.php index d9ab4db..b70376e 100644 --- a/src/Forms/Select.php +++ b/src/Forms/Select.php @@ -207,8 +207,13 @@ private function selectOther(): Element $input = $input->prop('aria-invalid true'); $input = $input->prop('aria-describedby ' . $this->warningId); } - $elements[] = Element::div($input, $label, self::warningMessage()); + $elements[] = Element::div($input, $label); } + + if (self::warningMessage() !== '') { + $elements[] = self::warningMessage(); + } + return Element::fieldset( Element::legend($this->label)->props(...$this->labelProperties), ...$elements diff --git a/tests/Forms/SelectTest.php b/tests/Forms/SelectTest.php index ae24790..ce6a798 100644 --- a/tests/Forms/SelectTest.php +++ b/tests/Forms/SelectTest.php @@ -12,6 +12,24 @@ class SelectTest extends TestCase { + #[Test] + public function ticket_36(): void // phpcs: ignore + { + $expected = <<Toppings

Choose at least one topping.

+ html; + + $result = (string) Select::create( + 'Toppings', + 'toppings', + ['mushroom' => 'Mushroom', 'olive' => 'Olive'], + [], + 'Choose at least one topping.' + )->checkbox(); + + parent::assertSame($expected, $result); + } + #[Test] public function warning_message_can_be_property_interface(): void // phpcs: ignore {