Skip to content

Commit 66b7f58

Browse files
author
matheo
committed
remove props from the attribute in the PropsNode
1 parent 2555d26 commit 66b7f58

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/TwigComponent/src/ComponentAttributes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function __toString(): string
3535
function (string $carry, string $key) {
3636
$value = $this->attributes[$key];
3737

38+
if (!\is_scalar($value) && null !== $value) {
39+
throw new \LogicException(sprintf('A "%s" prop was passed when creating the component. No matching %s property or mount() argument was found, so we attempted to use this as an HTML attribute. But, the value is not a scalar (it\'s a %s). Did you mean to pass this to your component or is there a typo on its name?', $key, $key, get_debug_type($value)));
40+
}
41+
3842
if (null === $value) {
3943
trigger_deprecation('symfony/ux-twig-component', '2.8.0', 'Passing "null" as an attribute value is deprecated and will throw an exception in 3.0.');
4044
$value = true;
@@ -144,4 +148,9 @@ public function add($stimulusDto): self
144148
// add the remaining attributes for values/classes
145149
return $clone->defaults($controllersAttributes);
146150
}
151+
152+
public function remove($key): void
153+
{
154+
unset($this->attributes[$key]);
155+
}
147156
}

src/TwigComponent/src/Twig/PropsNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function compile(Compiler $compiler): void
3131
foreach ($this->getAttribute('names') as $name) {
3232
$compiler
3333
->addDebugInfo($this)
34+
->write('$context[\'attributes\']->remove(\''.$name.'\');')
3435
->write('if (!isset($context[\''.$name.'\'])) {')
3536
;
3637

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<div class='user-card'>
1+
{% props user %}
2+
3+
<div {{ attributes }} class='user-card'>
24
<p>{{ user.name }}</p>
35
<p>{{ user.email }}</p>
46
</div>

0 commit comments

Comments
 (0)