Skip to content

Commit 3279945

Browse files
committed
fix(grid): allow binding style strings
fixes #8328
1 parent 2246e6b commit 3279945

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

packages/vuetify/src/util/mergeData.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,33 @@
33
* @license MIT
44
* @see https://github.com/alexsasharegan/vue-functional-data-merge
55
*/
6-
6+
/* eslint-disable max-statements */
77
import { VNodeData } from 'vue'
8+
import { camelize } from './helpers'
9+
10+
const pattern = {
11+
styleList: /;(?![^(]*\))/g,
12+
styleProp: /:(.*)/,
13+
} as const
14+
15+
function parseStyle (style: string) {
16+
const styleMap: Dictionary<any> = {}
17+
18+
for (const s of style.split(pattern.styleList)) {
19+
let [key, val] = s.split(pattern.styleProp)
20+
key = key.trim()
21+
if (!key) {
22+
continue
23+
}
24+
// May be undefined if the `key: value` pair is incomplete.
25+
if (typeof val === 'string') {
26+
val = val.trim()
27+
}
28+
styleMap[camelize(key)] = val
29+
}
30+
31+
return styleMap
32+
}
833

934
/**
1035
* Intelligently merges data for createElement.
@@ -13,7 +38,7 @@ import { VNodeData } from 'vue'
1338
*/
1439
export default function mergeData (...vNodeData: VNodeData[]): VNodeData
1540
export default function mergeData (): VNodeData {
16-
const mergeTarget: VNodeData & { [key: string]: any } = {}
41+
const mergeTarget: VNodeData & Dictionary<any> = {}
1742
let i: number = arguments.length
1843
let prop: string
1944
let event: string
@@ -31,6 +56,23 @@ export default function mergeData (): VNodeData {
3156
if (!Array.isArray(mergeTarget[prop])) {
3257
mergeTarget[prop] = []
3358
}
59+
60+
if (prop === 'style') {
61+
let style: any[]
62+
if (Array.isArray(arguments[i].style)) {
63+
style = arguments[i].style
64+
} else {
65+
style = [arguments[i].style]
66+
}
67+
for (let j = 0; j < style.length; j++) {
68+
const s = style[j]
69+
if (typeof s === 'string') {
70+
style[j] = parseStyle(s)
71+
}
72+
}
73+
arguments[i].style = style
74+
}
75+
3476
// Repackaging in an array allows Vue runtime
3577
// to merge class/style bindings regardless of type.
3678
mergeTarget[prop] = mergeTarget[prop].concat(arguments[i][prop])

0 commit comments

Comments
 (0)