Skip to content

Commit

Permalink
[11.x] Always inherit parent attributes (#53011)
Browse files Browse the repository at this point in the history
* Always inherit parent attributes

* tests
  • Loading branch information
royduin authored Oct 4, 2024
1 parent d9ecee5 commit d9bb513
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/View/ComponentAttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ComponentAttributeBag implements ArrayAccess, IteratorAggregate, JsonSeria
*/
public function __construct(array $attributes = [])
{
$this->attributes = $attributes;
$this->setAttributes($attributes);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/View/ViewComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\View\Component;
use Illuminate\View\ComponentAttributeBag;
use Illuminate\View\ComponentSlot;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

Expand Down Expand Up @@ -70,6 +71,22 @@ public function testAttributeParentInheritance(): void
$this->assertSame('class="override" type="submit"', (string) $component->attributes);
}

public function testSlotAttributeParentInheritance(): void
{
$attributes = new ComponentAttributeBag(['class' => 'bar', 'type' => 'button']);

$slot = new ComponentSlot('test', [
'class' => 'foo',
'attributes' => $attributes,
]);

$this->assertSame('class="foo bar" type="button"', (string) $slot->attributes);

// Test overriding parent class attributes
$slot->withAttributes(['class' => 'override', 'type' => 'submit']);
$this->assertSame('class="override" type="submit"', (string) $slot->attributes);
}

public function testPublicMethodsWithNoArgsAreConvertedToStringableCallablesInvokedAndNotCached()
{
$component = new TestSampleViewComponent;
Expand Down

0 comments on commit d9bb513

Please sign in to comment.