Skip to content

Commit 39f3e0f

Browse files
committed
wip
1 parent 432e9e9 commit 39f3e0f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/view/src/Elements/ViewComponentElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function compile(): string
138138
->prepend(
139139
// Open the current scope
140140
sprintf(
141-
'<?php (function ($attributes, $slots %s %s %s) { ?>',
141+
'<?php (function ($attributes, $slots %s %s %s) { extract($this->currentView?->data ?? [], EXTR_SKIP); ?>',
142142
$this->dataAttributes->isNotEmpty() ? (', ' . $this->dataAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ')) : '',
143143
$this->expressionAttributes->isNotEmpty() ? (', ' . $this->expressionAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ')) : '',
144144
$this->scopedVariables->isNotEmpty() ? (', ' . $this->scopedVariables->map(fn (string $name) => "\${$name}")->implode(', ')) : '',

tests/Integration/View/ViewComponentTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,4 +966,17 @@ public function test_default_slot_value(): void
966966
Default B
967967
HTML, $this->render('<x-test></x-test>'));
968968
}
969+
970+
public function test_view_variables_are_passed_into_the_component(): void
971+
{
972+
$this->registerViewComponent('x-a', '<x-slot />');
973+
974+
$html = $this->render(<<<'HTML'
975+
<x-a>
976+
{{ $title }}
977+
</x-a>
978+
HTML, title: 'test');
979+
980+
$this->assertSnippetsMatch('test', $html);
981+
}
969982
}

0 commit comments

Comments
 (0)