File tree Expand file tree Collapse file tree 2 files changed +44
-9
lines changed Expand file tree Collapse file tree 2 files changed +44
-9
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,27 @@ describe('defineCustomElement', () => {
210
210
customElements . define ( 'my-el-upgrade' , E )
211
211
expect ( el . shadowRoot . innerHTML ) . toBe ( `foo: hello` )
212
212
} )
213
+
214
+ // #5687
215
+ test ( 'using .xx-xx underlined naming conventions when used by WebComponent is reactive' , ( ) => {
216
+ const E = defineCustomElement ( {
217
+ props : {
218
+ maxAge : Number
219
+ } ,
220
+ render ( ) {
221
+ return `max age: ${ this . maxAge } `
222
+ }
223
+ } )
224
+ customElements . define ( 'my-element-hyphenate' , E )
225
+ const el = document . createElement ( 'my-element-hyphenate' ) as any
226
+ el . setAttribute ( 'max-age' , 0 )
227
+ container . appendChild ( el )
228
+ expect ( el . maxAge ) . toBe ( 0 )
229
+ el . maxAge = 50
230
+ expect ( el . maxAge ) . toBe ( 50 )
231
+ el [ 'max-age' ] = 100
232
+ expect ( el . maxAge ) . toBe ( 100 )
233
+ } )
213
234
} )
214
235
215
236
describe ( 'emits' , ( ) => {
Original file line number Diff line number Diff line change @@ -241,14 +241,10 @@ export class VueElement extends BaseClass {
241
241
242
242
// defining getter/setters on prototype
243
243
for ( const key of rawKeys . map ( camelize ) ) {
244
- Object . defineProperty ( this , key , {
245
- get ( ) {
246
- return this . _getProp ( key )
247
- } ,
248
- set ( val ) {
249
- this . _setProp ( key , val )
250
- }
251
- } )
244
+ this . _defineElementProperty ( key )
245
+ if ( hyphenate ( key ) !== key ) {
246
+ this . _defineElementProperty ( hyphenate ( key ) , key , false )
247
+ }
252
248
}
253
249
254
250
// apply CSS
@@ -266,9 +262,27 @@ export class VueElement extends BaseClass {
266
262
}
267
263
}
268
264
265
+ private _defineElementProperty (
266
+ key : string ,
267
+ originalKey = key ,
268
+ shouldReflect = true
269
+ ) {
270
+ Object . defineProperty ( this , key , {
271
+ get ( ) {
272
+ return this . _getProp ( originalKey )
273
+ } ,
274
+ set ( val ) {
275
+ this . _setProp ( originalKey , val , shouldReflect )
276
+ }
277
+ } )
278
+ }
279
+
269
280
protected _setAttr ( key : string ) {
270
281
let value = this . getAttribute ( key )
271
- if ( this . _numberProps && this . _numberProps [ key ] ) {
282
+ if (
283
+ this . _numberProps &&
284
+ ( this . _numberProps [ key ] || this . _numberProps [ camelize ( key ) ] )
285
+ ) {
272
286
value = toNumber ( value )
273
287
}
274
288
this . _setProp ( camelize ( key ) , value , false )
You can’t perform that action at this time.
0 commit comments