Skip to content

[7.x] Fix ComponentAttributeBag merge behaviour - #31932

Merged
taylorotwell merged 3 commits into
laravel:7.xfrom
mfullbrook:component-attribute-merge
Mar 12, 2020
Merged

[7.x] Fix ComponentAttributeBag merge behaviour#31932
taylorotwell merged 3 commits into
laravel:7.xfrom
mfullbrook:component-attribute-merge

Conversation

@mfullbrook

Copy link
Copy Markdown
Contributor

This PR is to fix the bug I raised in #31898. Below is an illustration of what this PR fixes.

With a component that defines some default attributes:

<table {{ $attributes->merge(['width' => '600', 'class' => 'mb-4']) }}>
  ...
</table>

If the component is used like this

<x-my-table width="100%" class="mt-2" />

We would expect the rendered template to be:

<table class="mb-4 mt-2" width="100%">
  ...
</table>

But the current implementation renders:

<table class="mb-4 mt-2" width="600">>
  ...
</table>

This PR fixes the implementation of ComponentAttributeBag::merge() so that it doesn't ignore attribute values specified in the template that is calling the component.

ViewComponentAttributeBagTest has been updated.

@GrahamCampbell GrahamCampbell changed the title [7.x]ComponentAttributeBag - merge() behaviour [7.x] Fix ComponentAttributeBag merge behaviour Mar 12, 2020
Comment thread tests/View/ViewComponentAttributeBagTest.php Outdated
Comment thread src/Illuminate/View/ComponentAttributeBag.php Outdated
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.

4 participants