diff --git a/src/Components/AttributeTraits/MaxlengthMinlengthAttributes.php b/src/Components/AttributeTraits/MaxlengthMinlengthAttributes.php index e344290c..bc612664 100644 --- a/src/Components/AttributeTraits/MaxlengthMinlengthAttributes.php +++ b/src/Components/AttributeTraits/MaxlengthMinlengthAttributes.php @@ -19,7 +19,7 @@ trait MaxlengthMinlengthAttributes * * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#client-side_validation */ - public string $maxlength = ''; + public int $maxlength = 0; /** * Valid for text, search, url, tel, email, and password, it defines the minimum string length (measured in UTF-16 @@ -34,17 +34,17 @@ trait MaxlengthMinlengthAttributes * * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#client-side_validation */ - public string $minlength = ''; + public int $minlength = 0; /** * Set the maxlength and minlength attributes. */ public function setMaxlengthMinlengthAttributes(AttributeCollection &$specificAttributes): void { - if (! empty($this->maxlength)) { + if ($this->maxlength >= 0) { $specificAttributes->add(['maxlength' => $this->maxlength]); } - if (! empty($this->minlength)) { + if ($this->minlength >= 0) { $specificAttributes->add(['minlength' => $this->minlength]); } } diff --git a/tests/Feature/Traits/MaxlengthMinlengthAttributesTest.php b/tests/Feature/Traits/MaxlengthMinlengthAttributesTest.php index d7e220f5..4fac4f2d 100644 --- a/tests/Feature/Traits/MaxlengthMinlengthAttributesTest.php +++ b/tests/Feature/Traits/MaxlengthMinlengthAttributesTest.php @@ -4,11 +4,11 @@ use T73biz\LwBits\Tests\TestSupport\Components\Forms\Inputs\MyEmail; it('can render with maxlength', function () { - Livewire::test(MyEmail::class, ['maxlength' => '10']) + Livewire::test(MyEmail::class, ['maxlength' => 10]) ->assertSee('maxlength="10"', false); }); it('can render with minlength', function () { - Livewire::test(MyEmail::class, ['minlength' => '5']) + Livewire::test(MyEmail::class, ['minlength' => 5]) ->assertSee('minlength="5"', false); });