Skip to content

Commit 9aadaa5

Browse files
committed
more detailed example
1 parent ef390b4 commit 9aadaa5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

documentation/docs/04-compiler-and-api/04-custom-elements-api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ When constructing a custom element, you can tailor several aspects by defining `
8787
name: { reflect: true, type: 'Number', attribute: 'element-index' }
8888
},
8989
extend: (customElementConstructor) => {
90+
// Extend the class so we can let it participate in HTML forms
9091
return class extends customElementConstructor {
9192
static formAssociated = true;
9293
9394
constructor() {
9495
super();
9596
this.attachedInternals = this.attachInternals();
9697
}
98+
99+
// Add the function here, not below in the component so that
100+
// it's always available, not just when the inner Svelte component
101+
// is mounted
102+
randomIndex() {
103+
this.elementIndex = Math.random();
104+
}
97105
};
98106
}
99107
}}
@@ -102,6 +110,10 @@ When constructing a custom element, you can tailor several aspects by defining `
102110
<script>
103111
export let elementIndex;
104112
export let attachedInternals;
113+
// ...
114+
function check() {
115+
attachedInternals.checkValidity();
116+
}
105117
</script>
106118
107119
...

0 commit comments

Comments
 (0)