diff --git a/packages/support/src/helpers.php b/packages/support/src/helpers.php index 6f253f19f73..dcc8f30678c 100644 --- a/packages/support/src/helpers.php +++ b/packages/support/src/helpers.php @@ -101,7 +101,7 @@ function prepare_inherited_attributes(ComponentAttributeBag $attributes): Compon $attributes->setAttributes( collect($originalAttributes) - ->filter(fn ($value, string $name): bool => ! str($name)->startsWith('x-')) + ->filter(fn ($value, string $name): bool => ! str($name)->startsWith(['x-', 'data-'])) ->mapWithKeys(fn ($value, string $name): array => [Str::camel($name) => $value]) ->merge($originalAttributes) ->all(), diff --git a/tests/src/Support/helpersTest.php b/tests/src/Support/helpersTest.php new file mode 100644 index 00000000000..1eec5125fce --- /dev/null +++ b/tests/src/Support/helpersTest.php @@ -0,0 +1,41 @@ + 'color:red', + ]); + + $attributes = prepare_inherited_attributes($bag); + + expect($attributes->getAttributes())->toBe([ + 'style' => 'color:red', + ]); +}); + +it('will prepare Alpine attributes', function () { + $bag = new ComponentAttributeBag([ + 'x-data' => '{foo:bar}', + ]); + + $attributes = prepare_inherited_attributes($bag); + + expect($attributes->getAttributes())->toBe([ + 'x-data' => '{foo:bar}', + ]); +}); + +it('will prepare data attributes', function () { + $bag = new ComponentAttributeBag([ + 'data-foo' => 'bar', + ]); + + $attributes = prepare_inherited_attributes($bag); + + expect($attributes->getAttributes())->toBe([ + 'data-foo' => 'bar', + ]); +});