more detailed example

pull/8991/head
Simon Holthausen 3 years ago
parent ef390b43b2
commit 9aadaa5cea

@ -87,6 +87,7 @@ When constructing a custom element, you can tailor several aspects by defining `
name: { reflect: true, type: 'Number', attribute: 'element-index' } name: { reflect: true, type: 'Number', attribute: 'element-index' }
}, },
extend: (customElementConstructor) => { extend: (customElementConstructor) => {
// Extend the class so we can let it participate in HTML forms
return class extends customElementConstructor { return class extends customElementConstructor {
static formAssociated = true; static formAssociated = true;
@ -94,6 +95,13 @@ When constructing a custom element, you can tailor several aspects by defining `
super(); super();
this.attachedInternals = this.attachInternals(); this.attachedInternals = this.attachInternals();
} }
// Add the function here, not below in the component so that
// it's always available, not just when the inner Svelte component
// is mounted
randomIndex() {
this.elementIndex = Math.random();
}
}; };
} }
}} }}
@ -102,6 +110,10 @@ When constructing a custom element, you can tailor several aspects by defining `
<script> <script>
export let elementIndex; export let elementIndex;
export let attachedInternals; export let attachedInternals;
// ...
function check() {
attachedInternals.checkValidity();
}
</script> </script>
... ...

Loading…
Cancel
Save