* @internal
*/
_removeChildStyle(type: ConcreteComponent): void
+ /**
+ * @internal
+ */
+ _setProp(
+ key: string,
+ val: any,
+ shouldReflect?: boolean,
+ shouldUpdate?: boolean,
+ ): void
}
expect(el.shadowRoot!.innerHTML).toMatchInlineSnapshot('"<div>foo</div>"')
})
- // # 5793
+ // #5793
test('set number value in dom property', () => {
const E = defineCustomElement({
props: {
expect(el.shadowRoot.innerHTML).toBe('max age: 50/type: number')
})
+ // #9006
+ test('should reflect default value', () => {
+ const E = defineCustomElement({
+ props: {
+ value: {
+ type: String,
+ default: 'hi',
+ },
+ },
+ render() {
+ return this.value
+ },
+ })
+ customElements.define('my-el-default-val', E)
+ container.innerHTML = `<my-el-default-val></my-el-default-val>`
+ const e = container.childNodes[0] as any
+ expect(e.value).toBe('hi')
+ })
+
test('support direct setup function syntax with extra options', () => {
const E = defineCustomElement(
props => {
// check if there are props set pre-upgrade or connect
for (const key of Object.keys(this)) {
if (key[0] !== '_' && declaredPropKeys.includes(key)) {
- this._setProp(key, this[key as keyof this], true, false)
+ this._setProp(key, this[key as keyof this])
}
}
return this._getProp(key)
},
set(val) {
- this._setProp(key, val)
+ this._setProp(key, val, true, true)
},
})
}
if (this._numberProps && this._numberProps[camelKey]) {
value = toNumber(value)
}
- this._setProp(camelKey, value, false)
+ this._setProp(camelKey, value, false, true)
}
/**
/**
* @internal
*/
- protected _setProp(
- key: string,
- val: any,
- shouldReflect = true,
- shouldUpdate = true,
- ) {
+ _setProp(key: string, val: any, shouldReflect = true, shouldUpdate = false) {
if (val !== this._props[key]) {
this._props[key] = val
if (shouldUpdate && this._instance) {