Skip to content

Commit e85a6e7

Browse files
Merge pull request #11 from CodeWithDennis/feature/empty-text
Added `emptyLabel` option
2 parents d9040b0 + c2ea873 commit e85a6e7

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ SelectTree::make('category_id')
3737

3838
// Ensures that only leaf nodes can be selected while preventing the selection of groups.
3939
->disabledBranchNode()
40+
41+
// Adjust the emptyLabel for when there are zero search results.
42+
->emptyLabel(__('No results found'))
4043

4144
// Show the count of children alongside the group's name.
4245
->withCount()

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function tree({
1414
clearable = true,
1515
isIndependentNodes = true,
1616
alwaysOpen = false,
17+
emptyText
1718
}) {
1819
return {
1920
state,
@@ -39,6 +40,7 @@ export default function tree({
3940
clearable,
4041
isIndependentNodes,
4142
alwaysOpen,
43+
emptyText
4244
});
4345

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

resources/views/select-tree.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
showTags: '{{ $getMultiple() }}',
2626
alwaysOpen: '{{ $getAlwaysOpen() }}',
2727
clearable: '{{ $getClearable() }}',
28+
emptyText: '{{ $getEmptyLabel() }}'
2829
})"
2930
>
3031
<div x-ref="tree"></div>

src/SelectTree.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SelectTree extends Field
2323

2424
protected bool $alwaysOpen = false;
2525

26+
protected string $emptyLabel;
27+
2628
protected bool $independent = true;
2729

2830
protected bool $clearable = true;
@@ -53,6 +55,13 @@ public function clearable(bool $clearable = true): static
5355
return $this;
5456
}
5557

58+
public function emptyLabel(string $emptyLabel): static
59+
{
60+
$this->emptyLabel = $emptyLabel;
61+
62+
return $this;
63+
}
64+
5665
public function independent(bool $independent = true): static
5766
{
5867
$this->independent = $independent;
@@ -128,6 +137,11 @@ public function getDisabledBranchNode(): bool
128137
return $this->evaluate($this->disabledBranchNode);
129138
}
130139

140+
public function getEmptyLabel(): string
141+
{
142+
return $this->evaluate($this->emptyLabel);
143+
}
144+
131145
public function tree(string $treeModel, string $treeParentKey, string $titleAttribute, Closure $modifyQueryUsing = null): static
132146
{
133147
$this->treeModel = $treeModel;

0 commit comments

Comments
 (0)