Cat/elements/cat-tab.html

41 lines
957 B
HTML

<cat-template>
<cat-children></cat-children>
</cat-template>
<script>
(function() {
let template = document.currentScript.ownerDocument.querySelector('cat-template');
customElements.define('cat-tab', class extends HTMLElement {
static get observedAttributes() { return ['label']; }
attributeChangedCallback(attr, oldValue, newValue) {
if (attr == 'label') {
if (this.control) {
this.control.setAttribute('label', newValue);
}
}
this[attr] = newValue;
}
constructor() {
super();
this.isAttached = false;
}
connectedCallback() {
template.cloneTo(this);
this.isAttached = true;
}
associateControl(node) {
this.control = node;
}
close() {
if (!this.isAttached) return;
this.parentNode.removeChild(this);
this.isAttached = false;
if (this.control) {
this.control.close();
}
}
});
})()
</script>