Skip to content

Commit

Permalink
Update CanDisableOptions.php
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin authored Jan 9, 2025
1 parent 4918745 commit 4370a7c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/forms/src/Components/Concerns/CanDisableOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
namespace Filament\Forms\Components\Concerns;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

trait CanDisableOptions
{
/**
* @var array<bool|Closure>
* @var array<bool | Closure>
*/
protected array $isOptionDisabled = [];

public function disableOptionWhen(bool | Closure $callback, bool $merge = false): static
public function disableOptionWhen(bool | Closure | null $callback, bool $merge = false): static
{
if ($merge) {
$this->isOptionDisabled[] = $callback;
} else {
$this->isOptionDisabled = [$callback];
$this->isOptionDisabled = Arr::wrap($callback);
}

return $this;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function getEnabledOptions(): array
public function isOptionDisabled($value, string $label): bool
{
return collect($this->isOptionDisabled)
->contains(fn ($isOptionDisabled) => $this->evaluate($isOptionDisabled, [
->contains(fn (bool | Closure $isOptionDisabled): bool => (bool) $this->evaluate($isOptionDisabled, [
'label' => $label,
'value' => $value,
]));
Expand All @@ -55,6 +56,6 @@ public function isOptionDisabled($value, string $label): bool
public function hasDynamicDisabledOptions(): bool
{
return collect($this->isOptionDisabled)
->contains(fn ($isOptionDisabled) => $isOptionDisabled instanceof Closure);
->contains(fn (bool | Closure $isOptionDisabled): bool => $isOptionDisabled instanceof Closure);
}
}

0 comments on commit 4370a7c

Please sign in to comment.