Skip to content

Commit

Permalink
Merge pull request #34 from jacksleight/fix/merging-class-attributes
Browse files Browse the repository at this point in the history
Fix merging class attributes
  • Loading branch information
timoisik committed Apr 26, 2023
2 parents 34c0b24 + 74b00ae commit 1afc115
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function mergeAttributes()
foreach ($moreAttributes as $key => $value) {
// class="foo bar"
if ($key === 'class') {
$attributes['class'] = trim($attributes['class'] ?? '' . ' ' . $value);
$attributes['class'] = trim(($attributes['class'] ?? '') . ' ' . $value);

continue;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Utils/HTMLTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Tiptap\Utils\HTML;

test('classes are merged properly', function () {
$attributes = [
['class' => 'a'],
['class' => 'b'],
];

$result = HTML::mergeAttributes(...$attributes);

expect($result)->toEqual(['class' => 'a b']);
});

0 comments on commit 1afc115

Please sign in to comment.