Skip to content

Commit

Permalink
Fix x-transition attribute handling in Blade components
Browse files Browse the repository at this point in the history
- Added test case for x-transition attribute
- Ensures x-transition doesn't get value='x-transition'

Fixes laravel#54015
  • Loading branch information
heynazmul committed Feb 4, 2025
1 parent 53091c2 commit 5f9919c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ public function testClassNamesCanBeGuessed()
{
$container = new Container;
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->once()->andReturn('App\\');
Container::setInstance($container);

Expand All @@ -392,6 +393,7 @@ public function testClassNamesCanBeGuessedWithNamespaces()
{
$container = new Container;
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->once()->andReturn('App\\');
Container::setInstance($container);

Expand Down Expand Up @@ -570,8 +572,8 @@ public function testPackagesClasslessComponents()
$container = new Container;
$container->instance(Application::class, $app = m::mock(Application::class));
$container->instance(Factory::class, $factory = m::mock(Factory::class));
$app->shouldReceive('getNamespace')->andReturn('App\\');
$factory->shouldReceive('exists')->andReturn(true);
$app->shouldReceive('getNamespace')->once()->andReturn('App\\');
$factory->shouldReceive('exists')->once()->andReturn(true);
Container::setInstance($container);

$result = $this->compiler()->compileTags('<x-package::anonymous-component :name="\'Taylor\'" :age="31" wire:model="foo" />');
Expand Down Expand Up @@ -915,6 +917,19 @@ public function testOriginalAttributesAreRestoredAfterRenderingChildComponentWit
$this->assertSame($attributes->get('other'), 'ok');
}

public function testTransitionAttributeIsHandledCorrectly()
{
$this->mockViewFactory();

$result = $this->compiler(['test' => TestTransitionComponent::class])
->compileTags('<x-test x-transition>content</x-test>');

$this->assertStringContainsString(
"'x-transition' => true",
$result
);
}

protected function mockViewFactory($existsSucceeds = true)
{
$container = new Container;
Expand Down
13 changes: 13 additions & 0 deletions tests/View/Blade/Components/TestTransitionComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Illuminate\Tests\View\Blade\Components;

use Illuminate\View\Component;

class TestTransitionComponent extends Component
{
public function render()
{
return '<div {{ $attributes }}>{{ $slot }}</div>';
}
}

0 comments on commit 5f9919c

Please sign in to comment.