Skip to content

Commit fd2266f

Browse files
committed
fix: Add support for customizable tree key in SelectTree
Introduce a `treeKey` property and associated methods to allow customization of the tree identifier. Updated Blade template to use the specified tree key for the `wire:key` attribute to ensure predictable component rendering. This is to address issue #141.
1 parent 68a38f8 commit fd2266f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

resources/views/select-tree.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
1414
<div
15-
wire:key="{{ rand() }}"
15+
wire:key="{{ $getTreeKey() }}"
1616
wire:ignore
1717
x-ignore
1818
@if (FilamentView::hasSpaMode())

src/SelectTree.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class SelectTree extends Field implements HasAffixActions
8888

8989
protected Closure|array|null $prepend = null;
9090

91+
protected Closure|string|null $treeKey = 'defaultTreeKey';
92+
9193
protected function setUp(): void
9294
{
9395
// Load the state from relationships using a callback function.
@@ -614,4 +616,16 @@ public function createOptionModalHeading(string|Closure|null $heading): static
614616

615617
return $this;
616618
}
619+
620+
public function treeKey(string $treeKey): static
621+
{
622+
$this->treeKey = $treeKey;
623+
624+
return $this;
625+
}
626+
627+
public function getTreeKey(): string
628+
{
629+
return $this->evaluate($this->treeKey);
630+
}
617631
}

0 commit comments

Comments
 (0)