Skip to content

Commit 64f99b5

Browse files
Merge pull request #154 from mgkimsal/3.x
fix: Add support for customizable tree key in SelectTree
2 parents 68a38f8 + d7d388e commit 64f99b5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

resources/views/select-tree.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
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
18-
@if (FilamentView::hasSpaMode())
18+
@if (FilamentView::hasSpaMode(url()->current()))
1919
ax-load="visible"
2020
@else
2121
ax-load

src/SelectTree.php

+16
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 = 'treeKey';
92+
9193
protected function setUp(): void
9294
{
9395
// Load the state from relationships using a callback function.
@@ -145,6 +147,8 @@ protected function setUp(): void
145147
$this->suffixActions([
146148
static fn (SelectTree $component): ?Action => $component->getCreateOptionAction(),
147149
]);
150+
151+
$this->treeKey('treeKey-'.rand());
148152
}
149153

150154
protected function buildTree(): Collection
@@ -614,4 +618,16 @@ public function createOptionModalHeading(string|Closure|null $heading): static
614618

615619
return $this;
616620
}
621+
622+
public function treeKey(string $treeKey): static
623+
{
624+
$this->treeKey = $treeKey;
625+
626+
return $this;
627+
}
628+
629+
public function getTreeKey(): string
630+
{
631+
return $this->evaluate($this->treeKey);
632+
}
617633
}

0 commit comments

Comments
 (0)