Skip to content

Commit

Permalink
fix(module:tooltip): keep tooltip visibility when trigger is null
Browse files Browse the repository at this point in the history
  • Loading branch information
stygian-desolator committed Mar 6, 2021
1 parent 0e326e7 commit 4da125c
Show file tree
Hide file tree
Showing 2 changed files with 22 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
23 changes: 21 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,22 @@ 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;
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 +364,8 @@ function getOverlayElementForTooltip(tooltip: NzTooltipBaseDirective): HTMLEleme
Manually
</a>
<a #alwaysShow nz-tooltip [nzTooltipTrigger]="trigger" [nzTooltipTitle]="'always show'" [nzTooltipVisible]="true">Always Show</a>
<div>
<button>A</button>
<button #inBtnGroup nz-tooltip nzTooltipTitle="title-string">B</button>
Expand All @@ -367,8 +385,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 4da125c

Please sign in to comment.