mirror of https://github.com/sveltejs/svelte
fix: support camelCase properties on custom elements (#9328)
while attributes are case insensitive, properties are not. to not introduce a breaking change, the lowercased variant is checked first. fixes #9325pull/9333/head
parent
6f508a011b
commit
9900c85acf
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: support camelCase properties on custom elements
|
@ -0,0 +1,7 @@
|
||||
export default {
|
||||
skip_if_ssr: true,
|
||||
skip_if_hydrate: true,
|
||||
html: `
|
||||
<my-custom-element>Hello World!</my-custom-element>
|
||||
`
|
||||
};
|
@ -0,0 +1,25 @@
|
||||
<script>
|
||||
class MyCustomElement extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this._obj = null;
|
||||
}
|
||||
|
||||
set camelCase(obj) {
|
||||
this._obj = obj;
|
||||
this.render();
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.render();
|
||||
}
|
||||
|
||||
render() {
|
||||
this.innerHTML = 'Hello ' + this._obj.text + '!';
|
||||
}
|
||||
}
|
||||
|
||||
window.customElements.define('my-custom-element', MyCustomElement);
|
||||
</script>
|
||||
|
||||
<my-custom-element camelCase={{ text: 'World' }} />
|
@ -0,0 +1,7 @@
|
||||
export default {
|
||||
skip_if_ssr: true,
|
||||
skip_if_hydrate: true,
|
||||
html: `
|
||||
<my-custom-inheritance-element>Hello World!</my-custom-inheritance-element>
|
||||
`
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
<script>
|
||||
class MyCustomElement extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this._obj = null;
|
||||
this._text = null;
|
||||
}
|
||||
|
||||
set text(text) {
|
||||
this._text = text;
|
||||
this.render();
|
||||
}
|
||||
|
||||
set camelCase(obj) {
|
||||
this._obj = obj;
|
||||
this.render();
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.render();
|
||||
}
|
||||
|
||||
render() {
|
||||
this.innerHTML = 'Hello ' + this._obj.text + this._text;
|
||||
}
|
||||
}
|
||||
|
||||
class Extended extends MyCustomElement {}
|
||||
|
||||
window.customElements.define('my-custom-inheritance-element', Extended);
|
||||
</script>
|
||||
|
||||
<my-custom-inheritance-element camelCase={{ text: 'World' }} text="!" />
|
Loading…
Reference in new issue