diff --git a/packages/forms/src/Components/Concerns/HasState.php b/packages/forms/src/Components/Concerns/HasState.php index f33f1d57d6..c7a45c913c 100644 --- a/packages/forms/src/Components/Concerns/HasState.php +++ b/packages/forms/src/Components/Concerns/HasState.php @@ -89,7 +89,7 @@ trait HasState return $this; } - public function callAfterStateUpdated(): static + public function callAfterStateUpdated(bool $shouldBubbleToParents = true, bool $isBubbling = false): static { foreach ($this->afterStateUpdated as $callback) { $runId = spl_object_id($callback) . md5(json_encode($this->getState())); @@ -103,6 +103,10 @@ trait HasState store($this)->push('executedAfterStateUpdatedCallbacks', value: $runId, iKey: $runId); } + if ($shouldBubbleToParents && ($isBubbling || $this->isLive())) { + $this->getContainer()->getParentComponent()?->callAfterStateUpdated(isBubbling: true); + } + return $this; } diff --git a/packages/forms/src/Components/Repeater.php b/packages/forms/src/Components/Repeater.php index b9db60da8a..a49e432817 100644 --- a/packages/forms/src/Components/Repeater.php +++ b/packages/forms/src/Components/Repeater.php @@ -162,21 +162,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract }); } - protected function callAfterStateUpdatedOnParents(Component $component, bool $isLive = false): void - { - if (! $isLive && ! $component->isLive()) { - return; - } - - $parent = $component->getContainer()->getParentComponent(); - - if ($parent) { - $parent->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($parent, true); - } - } - public function getAddAction(): Action { $action = Action::make($this->getAddActionName()) @@ -200,8 +185,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->collapsed(false, shouldMakeComponentCollapsible: false); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->button() ->size(ActionSize::Small) @@ -277,8 +260,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->collapsed(false, shouldMakeComponentCollapsible: false); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->button() ->size(ActionSize::Small) @@ -339,8 +320,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->collapsed(false, shouldMakeComponentCollapsible: false); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->iconButton() ->size(ActionSize::Small) @@ -380,8 +359,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->state($items); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->iconButton() ->size(ActionSize::Small) @@ -420,8 +397,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->state($items); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->iconButton() ->size(ActionSize::Small) @@ -460,8 +435,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->state($items); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->iconButton() ->size(ActionSize::Small) @@ -503,8 +476,6 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract $component->state($items); $component->callAfterStateUpdated(); - - $this->callAfterStateUpdatedOnParents($component); }) ->livewireClickHandlerEnabled(false) ->iconButton() diff --git a/packages/forms/src/Concerns/HasState.php b/packages/forms/src/Concerns/HasState.php index d6c65009f9..e27310531a 100644 --- a/packages/forms/src/Concerns/HasState.php +++ b/packages/forms/src/Concerns/HasState.php @@ -27,13 +27,13 @@ trait HasState { foreach ($this->getComponents(withHidden: true) as $component) { if ($component->getStatePath() === $path) { - $component->callAfterStateUpdated(); + $component->callAfterStateUpdated(shouldBubbleToParents: false); return true; } if (str($path)->startsWith("{$component->getStatePath()}.")) { - $component->callAfterStateUpdated(); + $component->callAfterStateUpdated(shouldBubbleToParents: false); } foreach ($component->getChildComponentContainers() as $container) {