Skip to content

Commit e50a7a4

Browse files
committed
Fix for hyphens in slot names
1 parent b037f74 commit e50a7a4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Tempest/View/src/Elements/ViewComponentElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function compile(): string
155155
)
156156
// Compile slots
157157
->replaceRegex(
158-
regex: '/<x-slot\s*(name="(?<name>\w+)")?((\s*\/>)|><\/x-slot>)/',
158+
regex: '/<x-slot\s*(name="(?<name>[\w-]+)")?((\s*\/>)|><\/x-slot>)/',
159159
replace: function ($matches) {
160160
$name = $matches['name'] ?: 'slot';
161161

tests/Integration/View/ViewComponentTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,29 @@ public function test_multiple_instances_of_custom_component_using_slots(): void
729729
HTML, $html);
730730
}
731731

732+
public function test_slots_with_hyphens(): void
733+
{
734+
$this->registerViewComponent('x-test', <<<'HTML'
735+
<div>
736+
<x-slot name="test-slot" />
737+
</div>
738+
HTML);
739+
740+
$html = $this->render(<<<'HTML'
741+
<x-test>
742+
<x-slot name="test-slot">
743+
Hi
744+
</x-slot>
745+
</x-test>
746+
HTML);
747+
748+
$this->assertSnippetsMatch(<<<'HTML'
749+
<div>
750+
Hi
751+
</div>
752+
HTML, $html);
753+
}
754+
732755
private function assertSnippetsMatch(string $expected, string $actual): void
733756
{
734757
$expected = str_replace([PHP_EOL, ' '], '', $expected);

0 commit comments

Comments
 (0)