Skip to content

Commit

Permalink
Merge 0c158aa into 0e326e7
Browse files Browse the repository at this point in the history
  • Loading branch information
stygian-desolator authored Mar 7, 2021
2 parents 0e326e7 + 0c158aa commit 19275ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/tooltip/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export abstract class NzTooltipBaseComponent implements OnDestroy, OnInit {
}

onClickOutside(event: MouseEvent): void {
if (!this.origin.elementRef.nativeElement.contains(event.target)) {
if (!this.origin.elementRef.nativeElement.contains(event.target) && this.nzTrigger !== null) {
this.hide();
}
}
Expand Down
24 changes: 22 additions & 2 deletions components/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { dispatchMouseEvent } from 'ng-zorro-antd/core/testing';
import { ComponentBed, createComponentBed } from 'ng-zorro-antd/core/testing/component-bed';
import { NzIconTestModule } from 'ng-zorro-antd/icon/testing';

import { NzTooltipBaseDirective } from './base';
import { NzTooltipBaseDirective, NzTooltipTrigger } from './base';
import { NzTooltipDirective } from './tooltip';
import { NzToolTipModule } from './tooltip.module';

Expand Down Expand Up @@ -156,6 +156,23 @@ describe('nz-tooltip', () => {
expect(overlayContainerElement.textContent).not.toContain(title);
expect(component.visibilityTogglingCount).toBe(2);
}));

it('should not hide tooltip when `nzTooltipTrigger` is null', fakeAsync(() => {
const title = 'always show';

component.trigger = null;
component.visible = true;
waitingForTooltipToggling();
dispatchMouseEvent(document.body, 'click');
waitingForTooltipToggling();
expect(overlayContainerElement.textContent).toContain(title);

component.trigger = 'click';
waitingForTooltipToggling();
dispatchMouseEvent(document.body, 'click');
waitingForTooltipToggling();
expect(overlayContainerElement.textContent).not.toContain(title);
}));
});

describe('content', () => {
Expand Down Expand Up @@ -348,6 +365,8 @@ function getOverlayElementForTooltip(tooltip: NzTooltipBaseDirective): HTMLEleme
Manually
</a>
<a #alwaysShow nz-tooltip [nzTooltipTrigger]="trigger" [nzTooltipTitle]="'always show'" [nzTooltipVisible]="visible">Always Show</a>
<div>
<button>A</button>
<button #inBtnGroup nz-tooltip nzTooltipTitle="title-string">B</button>
Expand All @@ -367,8 +386,9 @@ export class NzTooltipTestComponent {
titleTemplateDirective!: NzTooltipDirective;

@ViewChild('focusTooltip', { static: false }) focusTemplate!: ElementRef;
@ViewChild('alwaysShow', { static: false }) alwaysShow!: ElementRef;

trigger: string | null = 'click';
trigger: NzTooltipTrigger = 'click';

@ViewChild('inBtnGroup', { static: false }) inBtnGroup!: ElementRef;

Expand Down

0 comments on commit 19275ac

Please sign in to comment.