Skip to content

Commit 92e590d

Browse files
Added expandSelected option
1 parent 3ef4561 commit 92e590d

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

resources/dist/tree.js

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

resources/js/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default function tree({
1414
clearable = true,
1515
isIndependentNodes = true,
1616
alwaysOpen = false,
17-
emptyText
17+
emptyText,
18+
expandSelected = true
1819
}) {
1920
return {
2021
state,
@@ -40,7 +41,8 @@ export default function tree({
4041
clearable,
4142
isIndependentNodes,
4243
alwaysOpen,
43-
emptyText
44+
emptyText,
45+
expandSelected
4446
});
4547

4648
this.tree.srcElement.addEventListener('input', (e) => {

resources/views/select-tree.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
showTags: '{{ $getMultiple() }}',
2626
alwaysOpen: '{{ $getAlwaysOpen() }}',
2727
clearable: '{{ $getClearable() }}',
28-
emptyText: '{{ $getEmptyLabel() }}'
28+
emptyText: '{{ $getEmptyLabel() }}',
29+
expandSelected: '{{ $getExpandSelected() }}'
2930
})"
3031
>
3132
<div x-ref="tree"></div>

src/SelectTree.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SelectTree extends Field
2929

3030
protected bool $clearable = true;
3131

32+
protected bool $expandSelected = true;
33+
3234
protected bool $disabledBranchNode = false;
3335

3436
protected ?string $treeModel = null;
@@ -55,6 +57,13 @@ public function clearable(bool $clearable = true): static
5557
return $this;
5658
}
5759

60+
public function expandSelected(bool $expandSelected = true): static
61+
{
62+
$this->expandSelected = $expandSelected;
63+
64+
return $this;
65+
}
66+
5867
public function emptyLabel(string $emptyLabel): static
5968
{
6069
$this->emptyLabel = $emptyLabel;
@@ -102,6 +111,11 @@ public function getTree(): Collection|array
102111
return $this->evaluate($this->buildTree());
103112
}
104113

114+
public function getExpandSelected(): bool
115+
{
116+
return $this->evaluate($this->expandSelected);
117+
}
118+
105119
public function getIndependent(): bool
106120
{
107121
return $this->evaluate($this->independent);
@@ -160,7 +174,7 @@ private function buildTree(int $parent = null): array|Collection
160174
}
161175

162176
// Check if the treeModel is not set; if yes, return an empty collection.
163-
if (! $this->treeModel) {
177+
if (!$this->treeModel) {
164178
return collect();
165179
}
166180

@@ -169,7 +183,7 @@ private function buildTree(int $parent = null): array|Collection
169183
->where($this->treeParentKey, $parent);
170184

171185
// If we're not at the root level and a modification callback is provided, apply it.
172-
if (! $parent && $this->modifyQueryUsing) {
186+
if (!$parent && $this->modifyQueryUsing) {
173187
$defaultQuery = $this->evaluate($this->modifyQueryUsing, ['query' => $defaultQuery]);
174188
}
175189

0 commit comments

Comments
 (0)