3
3
namespace Filament \Forms \Components \Concerns ;
4
4
5
5
use Closure ;
6
+ use Illuminate \Support \Arr ;
6
7
use Illuminate \Support \Collection ;
7
8
8
9
trait CanDisableOptions
9
10
{
10
11
/**
11
- * @var array<bool| Closure>
12
+ * @var array<bool | Closure>
12
13
*/
13
14
protected array $ isOptionDisabled = [];
14
15
15
- public function disableOptionWhen (bool | Closure $ callback , bool $ merge = false ): static
16
+ public function disableOptionWhen (bool | Closure | null $ callback , bool $ merge = false ): static
16
17
{
17
18
if ($ merge ) {
18
19
$ this ->isOptionDisabled [] = $ callback ;
19
20
} else {
20
- $ this ->isOptionDisabled = [ $ callback] ;
21
+ $ this ->isOptionDisabled = Arr:: wrap ( $ callback) ;
21
22
}
22
23
23
24
return $ this ;
@@ -46,7 +47,7 @@ public function getEnabledOptions(): array
46
47
public function isOptionDisabled ($ value , string $ label ): bool
47
48
{
48
49
return collect ($ this ->isOptionDisabled )
49
- ->contains (fn ($ isOptionDisabled ) => $ this ->evaluate ($ isOptionDisabled , [
50
+ ->contains (fn (bool | Closure $ isOptionDisabled ): bool => ( bool ) $ this ->evaluate ($ isOptionDisabled , [
50
51
'label ' => $ label ,
51
52
'value ' => $ value ,
52
53
]));
@@ -55,6 +56,6 @@ public function isOptionDisabled($value, string $label): bool
55
56
public function hasDynamicDisabledOptions (): bool
56
57
{
57
58
return collect ($ this ->isOptionDisabled )
58
- ->contains (fn ($ isOptionDisabled ) => $ isOptionDisabled instanceof Closure);
59
+ ->contains (fn (bool | Closure $ isOptionDisabled ): bool => $ isOptionDisabled instanceof Closure);
59
60
}
60
61
}
0 commit comments