Skip to content

Commit 83a8eb3

Browse files
Merge pull request #192 from nathanheffley/add-options-for-not-showing-tags
Add show tags and tags count text options
2 parents 314f085 + 7660172 commit 83a8eb3

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ Return parent node value if all of its children are selected, instead of individ
143143
->isGroupedValue()
144144
```
145145

146+
Hide tags and display a count of selected items instead
147+
148+
```php
149+
->showTags(false)
150+
```
151+
152+
Customize the text shown if `showTags` is set to `false`, e.g. "{count} {tagsCountText}"
153+
154+
```php
155+
->tagsCountText('elements selected')
156+
```
157+
146158
Hide the clearable icon
147159

148160
```php

resources/dist/filament-select-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
@@ -12,6 +12,7 @@ export default function selectTree({
1212
disabled = false,
1313
isSingleSelect = true,
1414
showTags = true,
15+
tagsCountText = 'elements selected',
1516
clearable = true,
1617
isIndependentNodes = true,
1718
alwaysOpen = false,
@@ -58,6 +59,7 @@ export default function selectTree({
5859
disabled,
5960
isSingleSelect,
6061
showTags,
62+
tagsCountText,
6163
clearable,
6264
isIndependentNodes,
6365
alwaysOpen,

resources/views/select-tree.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
disabled: @js($isDisabled()),
3333
isSingleSelect: @js(!$getMultiple()),
3434
isIndependentNodes: @js($getIndependent()),
35-
showTags: @js($getMultiple()),
35+
showTags: @js($getShowTags()),
36+
tagsCountText: @js($getTagsCountText()),
3637
alwaysOpen: @js($getAlwaysOpen()),
3738
staticList: @js($getStaticList()),
3839
clearable: @js($getClearable()),

src/SelectTree.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class SelectTree extends Field implements HasAffixActions
5050

5151
protected null|int|string $parentNullValue = null;
5252

53+
protected bool|Closure|null $showTags = null;
54+
55+
protected string|Closure|null $tagsCountText = null;
56+
5357
protected bool $clearable = true;
5458

5559
protected bool $expandSelected = true;
@@ -426,6 +430,20 @@ public function getParentNullValue(): null|int|string
426430
return $this->evaluate($this->parentNullValue);
427431
}
428432

433+
public function showTags(bool|Closure $value = true): static
434+
{
435+
$this->showTags = $value;
436+
437+
return $this;
438+
}
439+
440+
public function tagsCountText(string|Closure $value): static
441+
{
442+
$this->tagsCountText = $value;
443+
444+
return $this;
445+
}
446+
429447
public function clearable(bool $clearable = true): static
430448
{
431449
$this->clearable = $clearable;
@@ -581,6 +599,16 @@ public function getMultiple(): bool
581599
);
582600
}
583601

602+
public function getShowTags(): bool
603+
{
604+
return $this->evaluate($this->showTags) ?? $this->getMultiple();
605+
}
606+
607+
public function getTagsCountText(): string
608+
{
609+
return $this->evaluate($this->tagsCountText) ?? 'elements selected';
610+
}
611+
584612
public function getClearable(): bool
585613
{
586614
return $this->evaluate($this->clearable);

0 commit comments

Comments
 (0)