UNPKG

@scania/tegel

Version:
105 lines (104 loc) 3.69 kB
import { Host, h } from "@stencil/core"; /** * @slot <default> - <b>Unnamed slot.</b> For the tab link or button. */ export class TdsNavigationTab { constructor() { this.disabled = false; this.selected = false; } /** @internal Method to set the Tab as selected. Used by the <tds-navigation-tabs> */ async setSelected(selected) { this.selected = selected; } connectedCallback() { const elements = this.host.querySelectorAll('button, a'); for (let index = 0; index < elements.length; index++) { const element = elements[index]; if (!element.getAttribute('aria-controls')) { console.warn('Tegel navigation-tab component: Interactive elements should have aria-controls attribute to link the tab to its corresponding panel'); } if (element.getAttribute('role') !== 'tab') { console.warn('Tegel navigation-tab component: Interactive elements should have attribute role="tab"'); } if (this.disabled) { element.setAttribute('aria-disabled', 'true'); } else { element.removeAttribute('aria-disabled'); } } } render() { return (h(Host, { key: '28ba6f5bedc4f2a31e5011e37bf92d3b38fa8abe' }, h("div", { key: 'ac5aad203d8a13dc42a8f9e99b2ccdd7c784c9af', class: `navigation-tab-item ${this.selected ? 'selected' : ''} ${this.disabled ? 'disabled' : ''}` }, h("slot", { key: 'da6292612753748f6cac68e0b282ecde642cb5b5' })))); } static get is() { return "tds-navigation-tab"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["navigation-tab.scss"] }; } static get styleUrls() { return { "$": ["navigation-tab.css"] }; } static get properties() { return { "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Disables the Tab." }, "attribute": "disabled", "reflect": false, "defaultValue": "false" } }; } static get states() { return { "selected": {} }; } static get methods() { return { "setSelected": { "complexType": { "signature": "(selected: boolean) => Promise<void>", "parameters": [{ "name": "selected", "type": "boolean", "docs": "" }], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<void>" }, "docs": { "text": "", "tags": [{ "name": "internal", "text": "Method to set the Tab as selected. Used by the <tds-navigation-tabs>" }] } } }; } static get elementRef() { return "host"; } }