Skip to content

Commit 18879a2

Browse files
committed
fix(dialog): use mouseleave by default
1 parent 9ef228b commit 18879a2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/dialog/dialog-config.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ export interface DialogConfig {
1414
content: string | TemplateRef<any>;
1515
/**
1616
* Parameter for triggering `Dialog` display.
17-
* With the release of v2.0 the type will just be "click" or "hover".
1817
*/
1918
trigger: "click" | "hover" | "mouseenter";
19+
/**
20+
* Parameter for triggering the `Dialog` close event.
21+
*/
22+
closeTrigger: "mouseout" | "mouseleave";
2023
/**
2124
* Parameter defining the placement in which the `Dialog` appears.
2225
* @type {Placement}

src/dialog/dialog.directive.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,35 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
3636
static dialogCounter = 0;
3737
/**
3838
* Title for the dialog
39-
* @type {string}
4039
*/
4140
@Input() title = "";
4241
/**
4342
* Dialog body content.
44-
* @type {(string | TemplateRef<any>)}
4543
*/
4644
@Input() ibmDialog: string | TemplateRef<any>;
4745
/**
4846
* Defines how the Dialog is triggered.(Hover and click behave the same on mobile - both respond to a single tap)
49-
* @type {("click" | "hover" | "mouseenter")}
5047
*/
5148
@Input() trigger: "click" | "hover" | "mouseenter" = "click";
49+
/**
50+
* Defines how the Dialog close event is triggered.
51+
*
52+
* [See here](https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseleave_event)
53+
* for more on the difference between `mouseleave` and `mouseout`.
54+
*
55+
* Defaults to `click` when `trigger` is set to `click`.
56+
*/
57+
@Input() closeTrigger: "mouseout" | "mouseleave" = "mouseleave";
5258
/**
5359
* Placement of the dialog, usually relative to the element the directive is on.
5460
*/
5561
@Input() placement = "left";
5662
/**
5763
* Class to add to the dialog container
58-
* @type {string}
5964
*/
6065
@Input() wrapperClass: string;
6166
/**
6267
* Spacing between the dialog and it's triggering element
63-
* @type {number}
6468
*/
6569
@Input() gap = 0;
6670
/**
@@ -117,7 +121,6 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
117121

118122
/**
119123
* Overrides 'touchstart' event to trigger a toggle on the Dialog.
120-
* @param {any} evt
121124
*/
122125
@HostListener("touchstart", ["$event"])
123126
onTouchStart(evt) {
@@ -135,6 +138,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
135138
parentRef: this.elementRef,
136139
gap: this.gap,
137140
trigger: this.trigger,
141+
closeTrigger: this.closeTrigger,
138142
appendInline: this.appendInline,
139143
wrapperClass: this.wrapperClass,
140144
data: this.data
@@ -160,7 +164,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
160164
// bind events for hovering or clicking the host
161165
if (this.trigger === "hover" || this.trigger === "mouseenter") {
162166
fromEvent(this.elementRef.nativeElement, "mouseenter").subscribe(() => this.toggle());
163-
fromEvent(this.elementRef.nativeElement, "mouseout").subscribe(() => this.close());
167+
fromEvent(this.elementRef.nativeElement, this.closeTrigger).subscribe(() => this.close());
164168
fromEvent(this.elementRef.nativeElement, "focus").subscribe(() => this.open());
165169
fromEvent(this.elementRef.nativeElement, "blur").subscribe(() => this.close());
166170
} else {
@@ -231,7 +235,6 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
231235
/**
232236
* Empty method for child classes to override and specify additional init steps.
233237
* Run after DialogDirective completes it's ngOnInit.
234-
* @protected
235238
*/
236239
protected onDialogInit() {}
237240
}

0 commit comments

Comments
 (0)