Skip to content

Commit 16c2189

Browse files
Introduce disabled options
1 parent 60aa02b commit 16c2189

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

resources/css/custom.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ html.dark .treeselect-list__item-checkbox-container {
183183
}
184184

185185
.treeselect-input__tags-element:hover .treeselect-input__tags-cross svg {
186-
stroke: rgba(var(--gray-950),var(--tw-text-opacity));
186+
stroke: rgba(var(--gray-950), var(--tw-text-opacity));
187187
}
188188

189189
html.dark .treeselect-input__tags-element:hover .treeselect-input__tags-cross svg {
@@ -238,3 +238,11 @@ html.dark .treeselect--disabled {
238238
.treeselect--disabled .treeselect-input__clear {
239239
display: none;
240240
}
241+
242+
.treeselect-list__item--disabled {
243+
cursor: not-allowed !important;
244+
}
245+
246+
html.dark .treeselect-list__item--disabled .treeselect-list__item-checkbox-container {
247+
background-color: hsl(0deg 0% 30.77% / 5%);
248+
}

resources/dist/custom.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SelectTree.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class SelectTree extends Field
4949

5050
protected string $direction = 'auto';
5151

52+
protected array $disabledOptions = [];
53+
5254
protected function setUp(): void
5355
{
5456
// Load the state from relationships using a callback function.
@@ -118,7 +120,7 @@ private function buildTreeFromResults($results, $parent = null): Collection
118120
// Group results by their parent IDs
119121
foreach ($results as $result) {
120122
$parentId = $result->{$this->getParentAttribute()};
121-
if (! isset($resultMap[$parentId])) {
123+
if (!isset($resultMap[$parentId])) {
122124
$resultMap[$parentId] = [];
123125
}
124126
$resultMap[$parentId][] = $result;
@@ -141,6 +143,7 @@ private function buildNode($result, $resultMap): array
141143
$node = [
142144
'name' => $result->{$this->getTitleAttribute()},
143145
'value' => $result->id,
146+
'disabled' => in_array($result->id, $this->getDisabledOptions())
144147
];
145148

146149
// Check if the result has children
@@ -251,6 +254,13 @@ public function independent(bool $independent = true): static
251254
return $this;
252255
}
253256

257+
public function disabledOptions(array $disabledOptions = []): static
258+
{
259+
$this->disabledOptions = $disabledOptions;
260+
261+
return $this;
262+
}
263+
254264
public function alwaysOpen(bool $alwaysOpen = true): static
255265
{
256266
$this->alwaysOpen = $alwaysOpen;
@@ -324,4 +334,9 @@ public function getDirection(): string
324334
{
325335
return $this->evaluate($this->direction);
326336
}
337+
338+
public function getDisabledOptions(): array
339+
{
340+
return $this->evaluate($this->disabledOptions);
341+
}
327342
}

0 commit comments

Comments
 (0)