diff --git a/src/Traits/Activatable.php b/src/Traits/Activatable.php index 8344e07..4d92462 100644 --- a/src/Traits/Activatable.php +++ b/src/Traits/Activatable.php @@ -22,9 +22,7 @@ public function isActive(): bool public function setActive(bool | callable $active = true): static { if (is_callable($active)) { - $this->active = $active($this); - - return $this; + $active = (bool)$active($this); } $this->active = $active; @@ -73,13 +71,15 @@ public function determineActiveForUrl(string $url, string $root = '/'): void /** * Set if current Activatable should be marked as an exact url match. - * - * @param bool $exactActive - * - * @return $this */ - public function setExactActive(bool $exactActive = true): static + public function setExactActive(bool | callable $exactActive = true): static { + if (is_callable($exactActive)) { + $this->exactActive = $exactActive($this); + + return $this; + } + $this->exactActive = $exactActive; return $this; diff --git a/tests/Traits/ActivatableTest.php b/tests/Traits/ActivatableTest.php index 1d4ca38..00d5108 100644 --- a/tests/Traits/ActivatableTest.php +++ b/tests/Traits/ActivatableTest.php @@ -26,3 +26,9 @@ return false; })->isActive())->toBeFalse(); }); + +it('can be set exact active via a callable', function () { + expect($this->activatable->setExactActive(function () { + return false; + })->isExactActive())->toBeFalse(); +});