-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-word blade component attributes aren't passed to child component #48956
Comments
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
Hello! I do not have a great amount of experience using Blade components, but I noticed something a while ago that made me realize I might not fully understand all the concepts about Blade components, and perhaps I was the one making mistakes. Maybe it is a bug, but I'm not sure. I'd prefer to share this here and see if someone with more experience can figure it out. Let's consider the scenario that @jacksleight mentioned above. "foo" anonymous Blade component: // resources/views/components/foo.blade.php
@props([
'one' => 'none',
'twoWord' => 'none',
])
<div>
One: {{ $one }} <br>
Two: {{ $twoWord }} <br>
</div> And the "bar" anonymous blade component // resources/views/components/bar.blade.php
<div>
<x-foo :attributes="$attributes" />
</div> If we use them like this on the welcome.blade.php file foo
<x-foo one="ok" two-word="ok" />
bar (kebab-case):
<x-bar one="ok" two-word="ok" />
bar (camelCase):
<x-bar one="ok" twoWord="ok" /> For some reason, the To make the kebab-case version work, I had to use @props([
'one' => 'none',
'twoWord' => 'none',
])
@aware(['twoWord'])
<div>
One: {{ $one }} <br>
Two: {{ $twoWord }} <br>
</div> But I think this is not how it's supposed to work. The docs says this about components:
Again, there is a good chance that I am misunderstanding something, but I just wanted to contribute this information with the bug the @jacksleight mentioned. |
Yeah my understanding is that you should always use kebab case in the tag and camel case in And that does work as expected if you make |
If you know it is a prop you should declare it as such in your wrapped component and pass it as a propped to the final child component. |
Ah OK, the thing is you wouldn't always know it's a prop. The idea here is that the While I could define all of |
Laravel Version
10.31.0
PHP Version
8.2.11
Database Driver & Version
No response
Description
When passing multi-word blade component attributes to a child component they don't make it to the child component. Probably best explained with an example:
Steps To Reproduce
I have a blade component called
foo
:And I have another blade component called
bar
which simply wrapsfoo
and passes everything down:If I render these two components like this:
I would expect this output:
However instead I get:
In both instances if I dump the attribute bag inside
foo
it's empty, which I would expect.The
two-word
/$twoWord
value just seems to disappear when passed viabar
, but theone
/$one
value works fine.foo
andbar
are both anonymous components.The text was updated successfully, but these errors were encountered: