Skip to content

Commit b290c22

Browse files
authored
Merge branch 'master' into issue.2857
2 parents 3fdeb0c + ea07b2a commit b290c22

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

src/button/base-icon-button.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export class BaseIconButton {
3333
"bottom" | "bottom-left" | "bottom-right" |
3434
"left" | "left-bottom" | "left-top" |
3535
"right" | "right-bottom" | "right-top" = "bottom";
36+
/**
37+
* **Experimental**: Use floating-ui to position the tooltip
38+
* This is not toggleable - should be assigned once
39+
*/
40+
@Input() autoAlign = false;
3641
/**
3742
* Set delay before tooltip is shown
3843
*/

src/button/icon-button.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { ButtonSize, ButtonType } from "./button.types";
3333
[highContrast]="highContrast"
3434
[isOpen]="isOpen"
3535
[align]="align"
36+
[autoAlign]="autoAlign"
3637
[enterDelayMs]="enterDelayMs"
3738
[leaveDelayMs]="leaveDelayMs"
3839
(click)="emitClickEvent($event, 'tooltip')">

src/button/icon-button.stories.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export default {
2222
kind: "primary",
2323
size: "md",
2424
isExpressive: "false",
25-
disabled: false
25+
disabled: false,
26+
autoAlign: false
2627
},
2728
argTypes: {
2829
align: {
@@ -41,7 +42,7 @@ export default {
4142
"danger--ghost"
4243
],
4344
control: { type: "select" },
44-
name: "cdsButton"
45+
name: "kind"
4546
},
4647
size: {
4748
options: ["sm", "md", "lg", "xl", "2xl"],
@@ -97,3 +98,40 @@ Basic.args = {
9798
"example-global-class": true
9899
}
99100
};
101+
102+
const AutoAlignTemplate = (args) => ({
103+
props: args,
104+
template: `
105+
<div style="height:3000px">
106+
Scrolling will update the position of the tooltip:
107+
<div style="position: absolute; top: 500px; left: 500px;">
108+
<cds-icon-button
109+
buttonId="icon-btn1"
110+
type="button"
111+
[kind]="kind"
112+
[size]="size"
113+
[align]="align"
114+
[autoAlign]="autoAlign"
115+
[isOpen]="isOpen"
116+
[buttonNgClass]="buttonNgClass"
117+
[buttonAttributes]="buttonAttributes"
118+
[disabled]="disabled"
119+
[description]="description"
120+
(click)="onClick($event)"
121+
(mouseenter)="onMouseEnter($event)"
122+
(mouseleave)="onMouseleave($event)"
123+
(focus)="onFocus($event)"
124+
(blur)="onBlur($event)">
125+
<svg class="cds--btn__icon" cdsIcon="copy" size="16"></svg>
126+
</cds-icon-button>
127+
</div>
128+
</div>
129+
`
130+
});
131+
export const WithAutoAlign = AutoAlignTemplate.bind({});
132+
WithAutoAlign.args = {
133+
autoAlign: true,
134+
description: "Icon Description",
135+
align: "top",
136+
isOpen: true
137+
};

src/table/table.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,10 @@ export class Table implements AfterViewInit, OnDestroy {
289289

290290
static focus(element: HTMLElement) {
291291
const focusElementList = getFocusElementList(element, tabbableSelectorIgnoreTabIndex);
292-
if (element.firstElementChild && element.firstElementChild.classList.contains("cds--table-sort") && focusElementList.length > 1) {
293-
focusElementList[1].focus();
294-
} else if (focusElementList.length > 0) {
292+
if (
293+
(element.firstElementChild?.classList.contains("cds--table-sort") && focusElementList.length > 1) ||
294+
focusElementList.length > 0
295+
) {
295296
focusElementList[0].focus();
296297
} else {
297298
element.focus();

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)