Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active March 2, 2023 23:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deebloo/65e2ef3b9bb93e469f56dfc4b0ede334 to your computer and use it in GitHub Desktop.
Save deebloo/65e2ef3b9bb93e469f56dfc4b0ede334 to your computer and use it in GitHub Desktop.
class MySelectElement extends HTMLElement {
constructor() {
super();
const observer = new MutationObserver((records) => {
for (let record of records) {
this.addItem(record.addedNodes);
this.removeItem(record.removedNodes);
}
});
customElements.whenDefined("my-option").then(() => {
this.addItems(this.children);
observer.observe(this, { childList: true });
});
}
addItems(nodes: Iterable<MyOptionElement>) {}
removeItems(nodes: Iterable<MyOptionElement>) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment