Skip to content

Commit 5bd35f2

Browse files
committed
feat: allow definition tooltip to be opened on hover
Signed-off-by: Akshat Patel <[email protected]>
1 parent edde579 commit 5bd35f2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/tooltip/definition-tooptip.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
3030
[attr.aria-expanded]="isOpen"
3131
[attr.aria-describedby]="isOpen ? id : null"
3232
(blur)="onBlur($event)"
33-
(focus)="onClick($event)"
34-
(mouseover)="onClick($event)"
35-
(click)="onClick($event)"
33+
(mousedown)="onClick($event)"
3634
type="button">
3735
<ng-content></ng-content>
3836
</button>
@@ -65,6 +63,8 @@ export class TooltipDefinition extends PopoverContainer {
6563
*/
6664
@Input() templateContext: any;
6765

66+
@Input() openOnHover = false;
67+
6868
constructor(
6969
protected elementRef: ElementRef,
7070
protected ngZone: NgZone,
@@ -97,6 +97,18 @@ export class TooltipDefinition extends PopoverContainer {
9797
this.handleChange(false, event);
9898
}
9999

100+
@HostListener("mouseenter", ["$event"])
101+
mouseenter(event) {
102+
if (this.openOnHover) {
103+
this.handleChange(true, event);
104+
}
105+
}
106+
107+
@HostListener("focusin", ["$event"])
108+
onFocus(event) {
109+
this.handleChange(true, event);
110+
}
111+
100112
public isTemplate(value) {
101113
return value instanceof TemplateRef;
102114
}

src/tooltip/definition-tooptip.stories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const Template = (args) => ({
6262
<p>Custom domains direct requests for your apps in this Cloud Foundry organization to a
6363
<cds-tooltip-definition
6464
[isOpen]="isOpen"
65+
[openOnHover]="openOnHover"
6566
[caret]="caret"
6667
[align]="align"
6768
(onOpen)="onOpen($event)"
@@ -101,6 +102,7 @@ const AutoAlignTemplate = (args) => ({
101102
<p>Custom domains direct requests for your apps in this Cloud Foundry organization to a
102103
<cds-tooltip-definition
103104
[isOpen]="isOpen"
105+
[openOnHover]="openOnHover"
104106
[caret]="caret"
105107
[align]="align"
106108
[autoAlign]="true"

0 commit comments

Comments
 (0)