Skip to content

Commit

Permalink
Merge pull request #10368 from titantwentyone/fix/data-attributes
Browse files Browse the repository at this point in the history
Fix to enable `data-` attributes to be parsed correctly
  • Loading branch information
danharrin authored Dec 19, 2023
2 parents bf4af5f + d2d97ea commit 2566cc3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/support/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
41 changes: 41 additions & 0 deletions tests/src/Support/helpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\View\ComponentAttributeBag;

use function Filament\Support\prepare_inherited_attributes;

it('will prepare attributes', function () {
$bag = new ComponentAttributeBag([
'style' => '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',
]);
});

0 comments on commit 2566cc3

Please sign in to comment.