Skip to content

Commit

Permalink
Fix component attributes rendering (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
squrious authored May 15, 2024
1 parent 2b9eebe commit d6be2cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Twig/StorybookEnvironmentConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Storybook\Twig;

use Symfony\UX\TwigComponent\ComponentAttributes;
use Twig\Environment;
use Twig\Extension\EscaperExtension;
use Twig\Extension\SandboxExtension;
use Twig\Sandbox\SecurityPolicyInterface;

Expand All @@ -22,6 +24,8 @@ public function configure(Environment $environment): void
{
$this->inner->configure($environment);

$environment->getExtension(EscaperExtension::class)->addSafeClass(ComponentAttributes::class, ['html']);

$environment->setExtensions([
new SandboxExtension($this->securityPolicy),
new StoryExtension(),
Expand Down
11 changes: 11 additions & 0 deletions tests/Integration/StoryRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,15 @@ public function testPassingPropsFromContextVariableWithSameName()

$this->assertEquals($renderer->render($storyWithFunction), $renderer->render($storyWithTag));
}

public function testComponentAttributeRendering()
{
self::bootKernel();

$renderer = static::getContainer()->get('storybook.story_renderer');

$story = new Story('story', '<twig:AnonymousComponent foo="bar"></twig:AnonymousComponent>', new Args());

$this->assertStringContainsString('foo="bar"', $renderer->render($story));
}
}

0 comments on commit d6be2cf

Please sign in to comment.