Replies: 1 comment 1 reply
-
|
I had the same problem too. In my case, I have the <!-- form -->
<x-form>
<x-file name="file_a" />
<x-textarea name="textarea" is-markdown />
</x-form>
<!-- textarea -->
@props(['isMarkdown' => false])
<fieldset>
@if ($isMarkdown)
<x-file name="attachments" multiple />
@endif
<textarea></textarea>
</fieldset>For the reasons you mentioned, the properties of the first input are also assigned to the second input. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I recently noticed behavior with Laravel's blade components that I found very unintuitive. If I'm rendering a component inside another component, properties passed to the parent component are automatically passed to the child component.
Here is an example of what is happening.
top-level blade:
The confirmation form class has no constructor arguments.
confirmation-form:
<form {{ $attributes }} method="post" action="{{ route('confirm') }}"> <x-form.input name="password"/> </form>Input component:
and blade:
<input name="{{ $name }}" id="{{ $id }}" {{ $attributes }}/>What I expected the rendered html to look like:
But what I got instead was this:
What happens is that any component with named properties gets them filled from
$attributesif it exists. So when we use a component inside a component, it takes the id from theComponentAttributeBag$attributesand passes it as a parameter to theInputclass. This behavior isn't documented anywhere.This is the code from
CompilesComponentsthat does it:I think it makes no sense that it works this way, but it looks like it was done on purpose and isn't a bug? Does this make sense to anyone?
Beta Was this translation helpful? Give feedback.
All reactions