Skip to content

Commit

Permalink
Fix attribute nesting on anonymous components (#36240)
Browse files Browse the repository at this point in the history
* fix attribute nesting

* Apply fixes from StyleCI (#36239)

* add test

* adjust order
  • Loading branch information
taylorotwell authored Feb 12, 2021
1 parent 07f31a7 commit a4a5116
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Illuminate/View/AnonymousComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function data()
{
$this->attributes = $this->attributes ?: $this->newAttributeBag();

return $this->data + ['attributes' => $this->attributes];
return array_merge(
optional($this->data['attributes'] ?? null)->getAttributes() ?: [],
$this->attributes->getAttributes(),
$this->data,
['attributes' => $this->attributes]
);
}
}
7 changes: 7 additions & 0 deletions tests/Integration/View/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public function test_appendable_attributes()
</div>', trim($view));
}

public function tested_nested_anonymous_attribute_proxying_works_correctly()
{
$view = View::make('uses-child-input')->render();

$this->assertSame('<input class="disabled-class" foo="bar" type="text" disabled />', trim($view));
}

protected function getEnvironmentSetUp($app)
{
$app['config']->set('view.paths', [__DIR__.'/templates']);
Expand Down
11 changes: 11 additions & 0 deletions tests/Integration/View/templates/components/base-input.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@props(['disabled' => false])

@php
if ($disabled) {
$class = 'disabled-class';
} else {
$class = 'not-disabled-class';
}
@endphp

<input {{ $attributes->merge(['class' => $class]) }} {{ $disabled ? 'disabled' : '' }} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<x-base-input foo="bar" :attributes="$attributes" />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<x-child-input type="text" :disabled="true" />

0 comments on commit a4a5116

Please sign in to comment.