Skip to content

Commit b9c9c12

Browse files
committed
tab component made non generic with string key
1 parent 2868213 commit b9c9c12

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/component-library/tab-group/src/tab-group.component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Signal, ElementRef, AfterViewInit } from '@angular/core';
22
import { Component, contentChildren, signal, computed, ChangeDetectionStrategy, input, viewChildren, output } from '@angular/core';
33
import { TabComponent } from './tab.component';
4-
import type { Primitive } from 'tableau-ui-angular/types';
54

65
@Component({
76
selector: 'tab-group',
@@ -11,7 +10,7 @@ import type { Primitive } from 'tableau-ui-angular/types';
1110
changeDetection: ChangeDetectionStrategy.OnPush,
1211
host: {},
1312
})
14-
export class TabGroupComponent<TKey extends Primitive> implements AfterViewInit {
13+
export class TabGroupComponent implements AfterViewInit {
1514
/**
1615
* Padding for the tab header, can be adjusted to fit design requirements.
1716
* @default '0.25rem 1.5rem'
@@ -35,7 +34,7 @@ export class TabGroupComponent<TKey extends Primitive> implements AfterViewInit
3534
alias: 'autoSelectFirstTab',
3635
});
3736

38-
protected readonly $tabs = contentChildren<TabComponent<TKey>>(TabComponent);
37+
protected readonly $tabs = contentChildren<TabComponent>(TabComponent);
3938
protected readonly $tabElements = viewChildren<ElementRef<HTMLDivElement>>('tab');
4039
// Signals to manage the selected index
4140
private readonly $_selectedIndex = signal(-1);
@@ -44,9 +43,9 @@ export class TabGroupComponent<TKey extends Primitive> implements AfterViewInit
4443
return this.$_selectedIndex;
4544
}
4645
// nullable Signal type needs to be set explicitly -> ng-packagr strips nullability
47-
readonly $selectedTab: Signal<TabComponent<TKey> | null> = computed(() => this.$tabs()[this.$selectedIndex()] ?? null);
46+
readonly $selectedTab: Signal<TabComponent | null> = computed(() => this.$tabs()[this.$selectedIndex()] ?? null);
4847

49-
readonly tabSelected = output<{ index: number; key: TKey | undefined; tab: TabComponent<TKey> }>();
48+
readonly tabSelected = output<{ index: number; key: string |undefined; tab: TabComponent }>();
5049
selectTabByIndex(index: number) {
5150
const tabs = this.$tabs();
5251

@@ -62,7 +61,7 @@ export class TabGroupComponent<TKey extends Primitive> implements AfterViewInit
6261
tab.afterActivate.emit();
6362
});
6463
}
65-
selectTabByKey(key: TKey) {
64+
selectTabByKey(key: string) {
6665
const tabs = this.$tabs();
6766
const index = tabs.findIndex((tab) => tab.$key() === key);
6867
if (index !== -1) {

projects/component-library/tab-group/src/tab.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { TemplateRef } from '@angular/core';
22
import { ChangeDetectionStrategy, Component, input, output, viewChild } from '@angular/core';
3-
import type { Primitive } from 'tableau-ui-angular/types';
43

54
@Component({
65
// eslint-disable-next-line @angular-eslint/component-selector
@@ -16,7 +15,7 @@ import type { Primitive } from 'tableau-ui-angular/types';
1615
`,
1716
changeDetection: ChangeDetectionStrategy.OnPush,
1817
})
19-
export class TabComponent<TKey extends Primitive> {
18+
export class TabComponent {
2019
readonly $headerTemplate = viewChild.required<TemplateRef<unknown>>('headerTemplate');
2120
readonly $contentTemplate = viewChild.required<TemplateRef<unknown>>('contentTemplate');
2221

@@ -27,7 +26,7 @@ export class TabComponent<TKey extends Primitive> {
2726
/**
2827
* Optional key if we want to select this tab with a key instead of index.
2928
*/
30-
readonly $key = input<TKey | undefined>(undefined, {
29+
readonly $key = input<string | undefined>(undefined, {
3130
alias: 'key',
3231
});
3332

0 commit comments

Comments
 (0)