Skip to content

Commit

Permalink
feat: add support for unknown tab elements that extend the base class
Browse files Browse the repository at this point in the history
  • Loading branch information
iOvergaard committed Mar 10, 2022
1 parent 5ebb5ef commit aca64f9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/uui-tabs/lib/uui-tab-group.element.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { css, html, LitElement } from 'lit';
import { queryAssignedNodes } from 'lit/decorators.js';
import { queryAssignedElements } from 'lit/decorators.js';

import { UUITabElement } from './uui-tab.element';

Expand All @@ -26,13 +26,24 @@ export class UUITabGroupElement extends LitElement {
`,
];

@queryAssignedNodes(undefined, true, 'uui-tab')
private slotNodes?: UUITabElement[];
@queryAssignedElements({
flatten: true,
selector: 'uui-tab, .uui-tab, [role=tab]',
})
private slotNodes?: HTMLElement[];

private tabElements: UUITabElement[] = [];

private setTabArray() {
this.tabElements = this.slotNodes ? this.slotNodes : [];
if (this.slotNodes) {
this.tabElements = this.slotNodes.filter(this.elementIsTab);
} else {
this.tabElements = [];
}
}

private elementIsTab(el: unknown): el is UUITabElement {
return el instanceof UUITabElement;
}

private onSlotChange() {
Expand All @@ -55,7 +66,7 @@ export class UUITabGroupElement extends LitElement {

private onTabActive = (e: MouseEvent) => {
//? should this contain stopPropagation?
const selectedElement: UUITabElement = e.target as UUITabElement;
const selectedElement = e.target as UUITabElement;
selectedElement.active = true;

const filtered = this.tabElements.filter(el => el !== selectedElement);
Expand Down

0 comments on commit aca64f9

Please sign in to comment.