Skip to content
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

[10.x] Fix kebab-case attributes not passed to children component data #49146

Closed
wants to merge 1 commit into from

Conversation

aguingand
Copy link

@aguingand aguingand commented Nov 27, 2023

Fixes #48956.

Today, when doing <x-test {{ $attributes }} />, kebab-cased attributes are ignored (for component class constructor parameters and anonymous component @props)

Class components

For compiled class components I have added ->toProps() to attributes array which convert attribute names to camelCase (diff). Kebab-case attributes are now passed to component constructor parameters. I have updated a test case to assert the data passed to Component::resolve() method.

Anonymous components

For anonymous components I have updated the data() method to transform attributes name to camelCase. I have added a test case for this method.

Attributes cleaning

In compiled component tags, I changed except() to exceptProps() to remove kebab-case attributes based on component constructor parameters (diff). I have updated a test case with user-id instead of userId to ensure kebab-case attributes are removed.

Naming considerations

The new ComponentAttributeBag::toProps() method may be not explicit enough, I can rename it if needed.

…anonymous component data. Extract attributes appropriately.
@taylorotwell
Copy link
Member

See my comment here: #48956

I'm afraid this will break all sorts of other use cases people may already be doing.

@aguingand
Copy link
Author

aguingand commented Nov 27, 2023

@taylorotwell Noted. I submitted this PR because it looked like a needed fix for the "attributes spread" feature.
Related PRs :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-word blade component attributes aren't passed to child component
2 participants