diff --git a/src/Tags/ComponentProxy.php b/src/Tags/ComponentProxy.php index 63a40fa1541..3a83555ee8c 100644 --- a/src/Tags/ComponentProxy.php +++ b/src/Tags/ComponentProxy.php @@ -15,6 +15,7 @@ class ComponentProxy extends Tags { public static $isolated = true; protected static $componentStack = []; + protected $rawParameters = []; private function makeComponentTagCompiler(): ComponentTagCompiler { @@ -24,6 +25,13 @@ private function makeComponentTagCompiler(): ComponentTagCompiler return new ComponentTagCompiler($bladeCompiler->getClassComponentAliases(), $bladeCompiler->getClassComponentNamespaces(), $bladeCompiler); } + public function setParameters($parameters) + { + $this->rawParameters = $parameters; + + return parent::setParameters($parameters); + } + public function index() { $___obLevel = ob_get_level(); @@ -38,7 +46,7 @@ public function index() $className = $tagCompiler->componentClass($componentName); $data = $this->params->except(['component_name___', 'component_bound___'])->all(); - $attributes = new ComponentAttributeBag($data); + $attributes = new ComponentAttributeBag($this->withLiteralBooleanStrings($data)); $constructorParameters = []; $scopeData = $this->context->all(); @@ -125,6 +133,15 @@ public function componentSlot() } } + protected function withLiteralBooleanStrings(array $data): array + { + return collect($data) + ->map(fn ($value, $key) => is_bool($value) && in_array($this->rawParameters[$key] ?? null, ['true', 'false'], true) + ? $this->rawParameters[$key] + : $value) + ->all(); + } + protected function escapeBoundAttributes(array $attributes): array { $bound = explode(',', $this->params->get('component_bound___', '')); diff --git a/tests/Antlers/Components/BooleanStringAttributesTest.php b/tests/Antlers/Components/BooleanStringAttributesTest.php new file mode 100644 index 00000000000..a1ae071f82c --- /dev/null +++ b/tests/Antlers/Components/BooleanStringAttributesTest.php @@ -0,0 +1,66 @@ + ['boolean_strings'], + 'blade component' => ['boolean_strings_blade'], + ]; + } + + #[Test] + #[DataProvider('componentProvider')] + public function written_true_and_false_attributes_keep_their_strings($component) + { + $this->assertStringStartsWith( + '