Skip to content

Commit b0b74a1

Browse files
authoredOct 22, 2022
fix(runtime-core): custom-element: ensure number casting of camelCase props. (fix: #5374) (#5377)
1 parent 54b6ba3 commit b0b74a1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
 

‎packages/runtime-dom/__tests__/customElement.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ describe('defineCustomElement', () => {
135135
test('attribute -> prop type casting', async () => {
136136
const E = defineCustomElement({
137137
props: {
138-
foo: Number,
138+
fooBar: Number, // test casting of camelCase prop names
139139
bar: Boolean,
140140
baz: String
141141
},
142142
render() {
143143
return [
144-
this.foo,
145-
typeof this.foo,
144+
this.fooBar,
145+
typeof this.fooBar,
146146
this.bar,
147147
typeof this.bar,
148148
this.baz,
@@ -151,7 +151,7 @@ describe('defineCustomElement', () => {
151151
}
152152
})
153153
customElements.define('my-el-props-cast', E)
154-
container.innerHTML = `<my-el-props-cast foo="1" baz="12345"></my-el-props-cast>`
154+
container.innerHTML = `<my-el-props-cast foo-bar="1" baz="12345"></my-el-props-cast>`
155155
const e = container.childNodes[0] as VueElement
156156
expect(e.shadowRoot!.innerHTML).toBe(
157157
`1 number false boolean 12345 string`
@@ -161,7 +161,7 @@ describe('defineCustomElement', () => {
161161
await nextTick()
162162
expect(e.shadowRoot!.innerHTML).toBe(`1 number true boolean 12345 string`)
163163

164-
e.setAttribute('foo', '2e1')
164+
e.setAttribute('foo-bar', '2e1')
165165
await nextTick()
166166
expect(e.shadowRoot!.innerHTML).toBe(
167167
`20 number true boolean 12345 string`

‎packages/runtime-dom/src/apiCustomElement.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,11 @@ export class VueElement extends BaseClass {
268268

269269
protected _setAttr(key: string) {
270270
let value = this.getAttribute(key)
271-
if (this._numberProps && this._numberProps[key]) {
271+
const camelKey = camelize(key)
272+
if (this._numberProps && this._numberProps[camelKey]) {
272273
value = toNumber(value)
273274
}
274-
this._setProp(camelize(key), value, false)
275+
this._setProp(camelKey, value, false)
275276
}
276277

277278
/**

0 commit comments

Comments
 (0)
Please sign in to comment.