('slot[name=header]')?.children || [])
] as TabHeader[];
const previous = children.find((c) => c.hasAttribute(activeAttribute));
// Remove active attributes from tab headers and tabs.
tabHeaders.forEach((header) => {
header.removeAttribute(activeHeaderAttribute);
header.requestUpdate();
});
children.forEach((element) => {
element.removeAttribute(activeAttribute);
});
// Set active tab-header and tab
tab.setAttribute(activeAttribute, '');
tabHeader.setAttribute(activeHeaderAttribute, '');
tabHeader.requestUpdate();
this.dispatchEvent(
new CustomEvent('tab-select', {
detail: {
previous: previous,
selected: tab
}
})
);
this.requestUpdate();
}
static override get styles() {
return [
super.styles,
css`
:host {
width:100%;
height:100%;
overflow: hidden;
}
/* Tab bar */
:host > .tab-bar {
display: flex;
flex-shrink: 0;
flex-direction: row;
align-items: center;
overflow-x: var(--omni-tab-group-tab-bar-overflow-x, auto);
overflow-y: var(--omni-tab-group-tab-bar-overflow-y, hidden);
width: var(--omni-tab-group-tab-bar-width, 100%);
height: var(--omni-tab-group-tab-bar-height, 50px);
border-bottom: var(--omni-tab-group-tab-bar-border-bottom, none);
background: var(--omni-tab-group-tab-bar-background-color, transparent);
}
/* CONTENT */
::slotted(*:not([active]):not([slot])) {
display: none !important;
}
`
];
}
protected override render(): TemplateResult {
/**
* Check what type of rendering option will be utilised the recommended implementation requires only nested omni-tab components the advanced implementation requires omni-tab-headers with associated omni-tab(s).
* If omni-tab-headers are nested the associated omni-tab requires the id attribute to be set to the corresponding omni-tab-headers for attribute.
*/
const tabHeaders = Array.from(this.querySelectorAll('omni-tab-header')).filter((oth) => oth.slot === 'header');
const tabContent = Array.from(this.querySelectorAll('omni-tab'));
if (tabContent.length > 0) {
if (!tabContent.find((c) => c.hasAttribute(activeAttribute) || c.active)) {
tabContent[0].setAttribute(activeAttribute, '');
const activeTabHeader = tabHeaders.find((x) => x.for === tabContent[0].id);
if (activeTabHeader) {
activeTabHeader.setAttribute(activeHeaderAttribute, '');
activeTabHeader.requestUpdate();
}
} else {
const activeTab = tabContent.find((c) => c.hasAttribute(activeAttribute) || c.active);
const activeTabHeader = tabHeaders.find((x) => x.for === activeTab?.id);
if (activeTabHeader) {
activeTabHeader.setAttribute(activeHeaderAttribute, '');
activeTabHeader.requestUpdate();
}
}
if (tabHeaders.length > 0) {
tabContent
.filter((t) => t.hasAttribute(disabledAttribute))
.forEach((t) => {
const header = tabHeaders.find((x) => x.for === t.id);
if (header) {
header.setAttribute(disabledHeaderAttribute, '');
header.requestUpdate();
}
});
}
}
return html`
this.selectTab(e.target as TabHeader)}">
this.requestUpdate()}">
${tabContent.map((tab) =>
tab.hasAttribute('header')
? html`
${tab.getAttribute('header')}
`
: nothing
)}
this.requestUpdate()}">
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'omni-tab-group': TabGroup;
}
}
// Custom Global Attributes
/**
* Indicates which slot is active
*/
export const activeAttribute = 'active';
export const disabledAttribute = 'disabled';
const activeHeaderAttribute = 'data-active';
const disabledHeaderAttribute = 'data-disabled';