Skip to content

Commit 4370a7c

Browse files
authored
Update CanDisableOptions.php
1 parent 4918745 commit 4370a7c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/forms/src/Components/Concerns/CanDisableOptions.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
namespace Filament\Forms\Components\Concerns;
44

55
use Closure;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Support\Collection;
78

89
trait CanDisableOptions
910
{
1011
/**
11-
* @var array<bool|Closure>
12+
* @var array<bool | Closure>
1213
*/
1314
protected array $isOptionDisabled = [];
1415

15-
public function disableOptionWhen(bool | Closure $callback, bool $merge = false): static
16+
public function disableOptionWhen(bool | Closure | null $callback, bool $merge = false): static
1617
{
1718
if ($merge) {
1819
$this->isOptionDisabled[] = $callback;
1920
} else {
20-
$this->isOptionDisabled = [$callback];
21+
$this->isOptionDisabled = Arr::wrap($callback);
2122
}
2223

2324
return $this;
@@ -46,7 +47,7 @@ public function getEnabledOptions(): array
4647
public function isOptionDisabled($value, string $label): bool
4748
{
4849
return collect($this->isOptionDisabled)
49-
->contains(fn ($isOptionDisabled) => $this->evaluate($isOptionDisabled, [
50+
->contains(fn (bool | Closure $isOptionDisabled): bool => (bool) $this->evaluate($isOptionDisabled, [
5051
'label' => $label,
5152
'value' => $value,
5253
]));
@@ -55,6 +56,6 @@ public function isOptionDisabled($value, string $label): bool
5556
public function hasDynamicDisabledOptions(): bool
5657
{
5758
return collect($this->isOptionDisabled)
58-
->contains(fn ($isOptionDisabled) => $isOptionDisabled instanceof Closure);
59+
->contains(fn (bool | Closure $isOptionDisabled): bool => $isOptionDisabled instanceof Closure);
5960
}
6061
}

0 commit comments

Comments
 (0)