From 6e69e7f2d070f68582532205f1ec4cc211c33169 Mon Sep 17 00:00:00 2001 From: Elisha Witte Date: Tue, 24 Sep 2024 13:49:59 +0200 Subject: [PATCH] Add html support for helptext --- src/Elements/Concerns/Groupable.php | 2 +- src/Elements/Group.php | 10 +++++++--- tests/Unit/GroupTest.php | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Elements/Concerns/Groupable.php b/src/Elements/Concerns/Groupable.php index 425462f..b2eaf21 100644 --- a/src/Elements/Concerns/Groupable.php +++ b/src/Elements/Concerns/Groupable.php @@ -9,7 +9,7 @@ /** * @method \Galahad\Aire\Elements\Element label(string|Htmlable $text) - * @method \Galahad\Aire\Elements\Element helpText(string $text) + * @method \Galahad\Aire\Elements\Element helpText(string|Htmlable $text) * @method \Galahad\Aire\Elements\Element validated($validation_state = 'valid') * @method \Galahad\Aire\Elements\Element valid() * @method \Galahad\Aire\Elements\Element invalid() diff --git a/src/Elements/Group.php b/src/Elements/Group.php index 14b5149..4f983fb 100644 --- a/src/Elements/Group.php +++ b/src/Elements/Group.php @@ -4,6 +4,7 @@ use Galahad\Aire\Aire; use Galahad\Aire\Contracts\NonInput; +use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\HtmlString; class Group extends Element implements NonInput @@ -77,7 +78,7 @@ public function __construct(Aire $aire, Form $form, Element $element) /** * Set the group's label * - * @param string|\Illuminate\Contracts\Support\Htmlable $text + * @param string|Htmlable $text * @return \Galahad\Aire\Elements\Group */ public function label($text): self @@ -99,8 +100,11 @@ public function variant($variant = null) return parent::variant($variant); } - - public function helpText(string $text): self + + /** + * @param string|Htmlable $text + */ + public function helpText($text): self { $this->view_data['help_text'] = $text; diff --git a/tests/Unit/GroupTest.php b/tests/Unit/GroupTest.php index c91011a..c51af50 100644 --- a/tests/Unit/GroupTest.php +++ b/tests/Unit/GroupTest.php @@ -3,6 +3,7 @@ namespace Galahad\Aire\Tests\Unit; use Galahad\Aire\Tests\TestCase; +use Illuminate\Support\HtmlString; use Illuminate\Support\Str; class GroupTest extends TestCase @@ -64,6 +65,16 @@ public function test_a_group_can_have_help_text(): void $this->assertSelectorTextEquals($input, 'div > small', 'Help text'); } + + public function test_a_group_can_have_html_help_text(): void + { + $input = $this->aire() + ->input() + ->helpText(new HtmlString('Help text')) + ->toHtml(); + + $this->assertSelectorTextEquals($input, 'div > small', 'Help text'); + } public function test_a_group_can_have_errors(): void {