File tree 2 files changed +8
-7
lines changed
2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -135,14 +135,14 @@ describe('defineCustomElement', () => {
135
135
test ( 'attribute -> prop type casting' , async ( ) => {
136
136
const E = defineCustomElement ( {
137
137
props : {
138
- foo : Number ,
138
+ fooBar : Number , // test casting of camelCase prop names
139
139
bar : Boolean ,
140
140
baz : String
141
141
} ,
142
142
render ( ) {
143
143
return [
144
- this . foo ,
145
- typeof this . foo ,
144
+ this . fooBar ,
145
+ typeof this . fooBar ,
146
146
this . bar ,
147
147
typeof this . bar ,
148
148
this . baz ,
@@ -151,7 +151,7 @@ describe('defineCustomElement', () => {
151
151
}
152
152
} )
153
153
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>`
155
155
const e = container . childNodes [ 0 ] as VueElement
156
156
expect ( e . shadowRoot ! . innerHTML ) . toBe (
157
157
`1 number false boolean 12345 string`
@@ -161,7 +161,7 @@ describe('defineCustomElement', () => {
161
161
await nextTick ( )
162
162
expect ( e . shadowRoot ! . innerHTML ) . toBe ( `1 number true boolean 12345 string` )
163
163
164
- e . setAttribute ( 'foo' , '2e1' )
164
+ e . setAttribute ( 'foo-bar ' , '2e1' )
165
165
await nextTick ( )
166
166
expect ( e . shadowRoot ! . innerHTML ) . toBe (
167
167
`20 number true boolean 12345 string`
Original file line number Diff line number Diff line change @@ -268,10 +268,11 @@ export class VueElement extends BaseClass {
268
268
269
269
protected _setAttr ( key : string ) {
270
270
let value = this . getAttribute ( key )
271
- if ( this . _numberProps && this . _numberProps [ key ] ) {
271
+ const camelKey = camelize ( key )
272
+ if ( this . _numberProps && this . _numberProps [ camelKey ] ) {
272
273
value = toNumber ( value )
273
274
}
274
- this . _setProp ( camelize ( key ) , value , false )
275
+ this . _setProp ( camelKey , value , false )
275
276
}
276
277
277
278
/**
You can’t perform that action at this time.
0 commit comments