Skip to content

Commit

Permalink
Merge branch 'master' into fix-2911-userouter-sidenav
Browse files Browse the repository at this point in the history
  • Loading branch information
klaascuvelier authored Jun 12, 2024
2 parents 7085c56 + e167388 commit 68402cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/tabs/tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ import {
[ngStyle]="{'display': active ? null : 'none'}"
[attr.aria-labelledby]="id + '-header'"
aria-live="polite">
<ng-template
*ngIf="isTemplate(tabContent)"
[ngTemplateOutlet]="tabContent"
[ngTemplateOutletContext]="{ $implicit: templateContext }">
</ng-template>
<ng-content></ng-content>
</div>
`
Expand Down Expand Up @@ -111,11 +116,18 @@ export class Tab implements OnInit {
@Input() set cacheActive(shouldCache: boolean) {
this._cacheActive = shouldCache;
}
/**
* Allows life cycle hooks to be called on the rendered content
*/
@Input() tabContent: TemplateRef<any>;
/**
* Optional data for templates passed as implicit context
*/
@Input() templateContext: any;
/**
* Value 'selected' to be emitted after a new `Tab` is selected.
*/
@Output() selected: EventEmitter<void> = new EventEmitter<void>();

/**
* Used to set the id property on the element.
*/
Expand Down Expand Up @@ -150,4 +162,8 @@ export class Tab implements OnInit {
shouldRender() {
return this.active || this.cacheActive;
}

public isTemplate(value) {
return value instanceof TemplateRef;
}
}
13 changes: 11 additions & 2 deletions src/tabs/tabs.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ const Template = (args) => ({
[cacheActive]="cacheActive">
<cds-tab heading="one">Tab Content 1</cds-tab>
<cds-tab heading="two">Tab Content 2</cds-tab>
<cds-tab heading="three">Tab Content 3</cds-tab>
<cds-tab heading="three">Tab Content 3</cds-tab>
<cds-tab heading="three" [tabContent]="three"></cds-tab>
<cds-tab heading="four" [tabContent]="four"></cds-tab>
</cds-tabs>
<!-- Use templates if you would like to have lifecycle hooks called when cacheActive is false -->
<ng-template #three>
Tab Content 3
</ng-template>
<ng-template #four>
Tab Content 4
</ng-template>
`
});
export const Basic = Template.bind({});
Expand Down

0 comments on commit 68402cd

Please sign in to comment.