From 46c415fcbfeb9bdd42048c15567d8545741d97e3 Mon Sep 17 00:00:00 2001 From: Krzysztof Grzelak Date: Mon, 1 Jul 2024 19:07:51 +0200 Subject: [PATCH] Update elements type set --- src/BaseItem.php | 20 +++++++++++++++++++- tests/FormInputTest.php | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/BaseItem.php b/src/BaseItem.php index 90895be..8963cd0 100644 --- a/src/BaseItem.php +++ b/src/BaseItem.php @@ -78,7 +78,25 @@ public function setName(string $name): static return $this; } - public function type(string $type): static + /** + * @description Set the type of the element + * @param string|null $type + * @return static + */ + public function type(?string $type = null): static + { + $this->attributes->setAttribute('type', $type); + + return $this; + } + + /** + * @deprecated Use type() instead + * @description Set the type of the element + * @param string|null $type + * @return static + */ + public function setType(?string $type = null): static { $this->attributes->setAttribute('type', $type); diff --git a/tests/FormInputTest.php b/tests/FormInputTest.php index cb9d455..c94a786 100644 --- a/tests/FormInputTest.php +++ b/tests/FormInputTest.php @@ -82,4 +82,18 @@ public function testDontShowErrorsWhenDisabledInConfiguration(): void $this->assertEquals('', $item); } + + public function testCanCreateInputWithCustomType(): void + { + $item = LaravelForm::input()->type('password'); + + $this->assertEquals('', $item); + } + + public function testCanCreateInputWithoutType() + { + $item = LaravelForm::input()->type(null); + + $this->assertEquals('', $item); + } }