Skip to content

Commit cb12fd9

Browse files
authored
Merge pull request #2854 from Licen-it/tooltip-data
feat(Tooltip, TooltipDefinition): expose data input to be passed as template outlet context when rendering the tooltip
2 parents fa59676 + b9c5fc7 commit cb12fd9

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/button/icon-button.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default {
4141
"danger--ghost"
4242
],
4343
control: { type: "select" },
44-
name: "cdsButton"
44+
name: "kind"
4545
},
4646
size: {
4747
options: ["sm", "md", "lg", "xl", "2xl"],

src/tooltip/definition-tooptip.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
4141
role="tooltip">
4242
<span class="cds--popover-content cds--definition-tooltip">
4343
<ng-container *ngIf="!isTemplate(description)">{{description}}</ng-container>
44-
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description"></ng-template>
44+
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description" [ngTemplateOutletContext]="{ $implicit: templateContext }"></ng-template>
4545
<span *ngIf="autoAlign" class="cds--popover-caret cds--popover--auto-align"></span>
4646
</span>
4747
<span *ngIf="!autoAlign" class="cds--popover-caret"></span>
@@ -57,6 +57,10 @@ export class TooltipDefinition extends PopoverContainer {
5757
* The string or template content to be exposed by the tooltip.
5858
*/
5959
@Input() description: string | TemplateRef<any>;
60+
/**
61+
* Optional data for templates passed as implicit context
62+
*/
63+
@Input() templateContext: any;
6064

6165
constructor(
6266
protected elementRef: ElementRef,

src/tooltip/tooltip.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
3939
<ng-container *ngIf="!disabled">
4040
<span class="cds--popover-content cds--tooltip-content">
4141
<ng-container *ngIf="!isTemplate(description)">{{description}}</ng-container>
42-
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description"></ng-template>
42+
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description" [ngTemplateOutletContext]="{ $implicit: templateContext }"></ng-template>
4343
<span *ngIf="autoAlign" class="cds--popover-caret cds--popover--auto-align"></span>
4444
</span>
4545
<span *ngIf="!autoAlign" class="cds--popover-caret"></span>
@@ -69,6 +69,10 @@ export class Tooltip extends PopoverContainer implements AfterContentChecked {
6969
* The string or template content to be exposed by the tooltip.
7070
*/
7171
@Input() description: string | TemplateRef<any>;
72+
/**
73+
* Optional data for templates passed as implicit context
74+
*/
75+
@Input() templateContext: any
7276

7377
@ViewChild("contentWrapper") wrapper: ElementRef<HTMLSpanElement>;
7478

0 commit comments

Comments
 (0)