Skip to content

Commit 04bb6a7

Browse files
committed
fix: handle 1 option values
1 parent 5451de4 commit 04bb6a7

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/SelectTree.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,23 @@ private function buildTreeFromResults($results, $parent = null): Collection
223223

224224
// Recursively build the tree starting from the root (null parent)
225225
$rootResults = $resultMap[$parent] ?? [];
226-
foreach ($rootResults as $result) {
227-
// Build a node and add it to the tree
228-
$node = $this->buildNode($result, $resultMap, $disabledOptions, $hiddenOptions);
229-
$tree->push($node);
226+
227+
// If we have no root results but we have results, and we're using modifyQueryUsing,
228+
// it means the query was filtered and might not have proper root items.
229+
// In this case, show all results as root items to prevent empty trees.
230+
if (empty($rootResults) && !empty($results) && $this->modifyQueryUsing) {
231+
foreach ($results as $result) {
232+
// Build a node and add it to the tree
233+
$node = $this->buildNode($result, $resultMap, $disabledOptions, $hiddenOptions);
234+
$tree->push($node);
235+
}
236+
} else {
237+
// Normal tree building - only show items that are actually root items
238+
foreach ($rootResults as $result) {
239+
// Build a node and add it to the tree
240+
$node = $this->buildNode($result, $resultMap, $disabledOptions, $hiddenOptions);
241+
$tree->push($node);
242+
}
230243
}
231244

232245
return $tree;

0 commit comments

Comments
 (0)