diff --git a/packages/forms/.stubs.php b/packages/forms/.stubs.php index d0e1bd5517..decfcdfaa8 100644 --- a/packages/forms/.stubs.php +++ b/packages/forms/.stubs.php @@ -26,6 +26,8 @@ namespace Livewire\Features\SupportTesting { public function assertFormFieldIsVisible(string $fieldName, string $formName = 'form'): static {} + public function assertFormComponentExists(string $componentKey, string | Closure $formName = 'form', ?Closure $checkComponentUsing = null): static {} + public function mountFormComponentAction(string | array $component, string | array $name, array $arguments = [], string $formName = 'form'): static {} public function unmountFormComponentAction(): static {} diff --git a/packages/forms/src/Concerns/HasComponents.php b/packages/forms/src/Concerns/HasComponents.php index 617ee85136..6cf8fc9f91 100644 --- a/packages/forms/src/Concerns/HasComponents.php +++ b/packages/forms/src/Concerns/HasComponents.php @@ -88,7 +88,7 @@ trait HasComponents } $carry[$componentKey] = $component; - + return $carry; }, initial: []); } diff --git a/tests/src/Forms/FormsTest.php b/tests/src/Forms/FormsTest.php index 38f6e8c209..1263409e07 100644 --- a/tests/src/Forms/FormsTest.php +++ b/tests/src/Forms/FormsTest.php @@ -1,5 +1,6 @@ assertFormFieldIsVisible('visible', 'barForm'); }); +it('has layout components', function () { + livewire(TestComponentWithForm::class) + ->assertFormComponentExists('section') + ->assertFormComponentExists('nested.section') + ->assertFormComponentExists('nested.section', function (Section $section): bool { + return $section->getHeading() === 'I am nested'; + }); +}); + class TestComponentWithForm extends Livewire { public function form(Form $form): Form @@ -108,6 +118,13 @@ class TestComponentWithForm extends Livewire ->hidden(), TextInput::make('visible'), + + Section::make() + ->key('section') + ->schema([ + Section::make('I am nested') + ->key('nested.section'), + ]), ]); }