Skip to content

Commit 2c47465

Browse files
committed
Change for style binding
1 parent fd5522b commit 2c47465

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/Compiler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ protected function handleObjectBinding(array $items, array &$dynamicValues, bool
802802
if (preg_match($regexObjectElements, $item, $matchElement)) {
803803
$dynamicValues[] = $this->builder->prepareBindingOutput(
804804
$isStyle && !$matchElement['isString']
805-
? '\'' . $matchElement['class'] . ':\' + ' . $matchElement['condition']
805+
? '\'' . $this->camelCaseToKebabCase($matchElement['class']) . ':\' + ' . $matchElement['condition']
806806
: $this->builder->refactorCondition($matchElement['condition']) . ' ? \'' . $matchElement['class'] . '\'',
807807
$twigOutput
808808
);
@@ -1530,4 +1530,9 @@ private function replaceAttributeWithIfConditionPlaceholders(string $html): stri
15301530

15311531
return $html;
15321532
}
1533+
1534+
private function camelCaseToKebabCase(string $text): string
1535+
{
1536+
return strtolower(preg_replace('/([a-z])([A-Z])/', '\1-\2', $text));
1537+
}
15331538
}

tests/fixtures/vue-bind/bindings-style.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@
2020
<span style="{{ 'background-color:' ~ color }};">
2121
test
2222
</span>
23+
<span style="{{ 'background-color:' ~ color }};">
24+
test
25+
</span>
2326
</div>

tests/fixtures/vue-bind/bindings-style.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
<span :style="'background-color:' + color">
2222
test
2323
</span>
24+
<span :style="{backgroundColor: color}">
25+
test
26+
</span>
2427
</div>
2528
</template>

0 commit comments

Comments
 (0)