diff --git a/src/BaseElement.php b/src/BaseElement.php index d10d0d5..d1d4235 100644 --- a/src/BaseElement.php +++ b/src/BaseElement.php @@ -7,6 +7,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; use Illuminate\Support\Str; +use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; use Spatie\Html\Exceptions\InvalidChild; use Spatie\Html\Exceptions\InvalidHtml; @@ -14,6 +15,8 @@ abstract class BaseElement implements Htmlable, HtmlElement { + use Conditionable; + use Macroable { __call as __macro_call; } diff --git a/tests/BaseElementTest.php b/tests/BaseElementTest.php index 9482fc8..3e33f46 100644 --- a/tests/BaseElementTest.php +++ b/tests/BaseElementTest.php @@ -309,3 +309,12 @@ class Div extends BaseElement '
', Div::create()->aria('describedby', 'bar')->render() ); + + +it('can make use of the conditionable helper') + ->assertHtmlStringEqualsHtmlString( + '', + Div::create() + ->when(false, fn(BaseElement $element) => $element->data('foo', 'bar')) + ->render() + );