Skip to content

Commit

Permalink
feat(module:tooltip,popover,popconfirm): do not show tooltip when it'…
Browse files Browse the repository at this point in the history
…s content is empty

close #631
  • Loading branch information
wilsoncook committed Dec 10, 2017
1 parent e712d87 commit 54ff189
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/components/tooltip/nz-tooltip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export class NzToolTipComponent {
}

show(): void {
this.nzVisible = true;
if (!this.isContentEmpty()) {
this.nzVisible = true;
}
}

hide(): void {
Expand Down Expand Up @@ -165,4 +167,9 @@ export class NzToolTipComponent {
}

constructor(private _cdr: ChangeDetectorRef) { }

private isContentEmpty(): boolean {
// return this.nzTemplate ? !(this.nzTemplate.elementRef.nativeElement as HTMLElement).hasChildNodes() : this.nzTitle === '';
return this.nzTemplate ? false : (this.nzTitle === '' || this.nzTitle == null); // Pity, can't detect whether nzTemplate is empty due to can't get it's content before shown up
}
}
17 changes: 7 additions & 10 deletions src/components/tooltip/nz-tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ export class NzTooltipDirective implements AfterViewInit {
// [NOTE] Here hard coded, and nzTitle used only under NzTooltipDirective currently.
// The inherited class such as NzPopconfirmDirective should override this property if want using this property.
@Input('nz-tooltip')
get nzTitle(): string { return this.tooltip.nzTitle; }
set nzTitle(title: string) {
if (this.isDynamicTooltip) {
this.tooltip.nzTitle = title;
}
}

get nzTitle(): string {
return this.tooltip.nzTitle;
}

@HostBinding('class.ant-tooltip-open') isTooltipOpen;

private tooltip: NzToolTipComponent;
Expand All @@ -41,15 +38,15 @@ export class NzTooltipDirective implements AfterViewInit {
private resolver: ComponentFactoryResolver,
private renderer: Renderer2,
@Optional() tooltip: NzToolTipComponent) {
let normalizedTooltip: NzToolTipComponent = tooltip;

this.tooltip = tooltip;
// Support faster tooltip mode: <a nz-tooltip="xxx"></a>. [NOTE] Used only under NzTooltipDirective currently.
if (!normalizedTooltip) {
if (!this.tooltip) {
const factory = this.resolver.resolveComponentFactory(NzToolTipComponent);
normalizedTooltip = this.hostView.createComponent(factory).instance;
this.tooltip = this.hostView.createComponent(factory).instance;
this.isDynamicTooltip = true;
}
normalizedTooltip.setOverlayOrigin(this);
this.tooltip = normalizedTooltip;
this.tooltip.setOverlayOrigin(this);
}

ngAfterViewInit(): void {
Expand All @@ -58,7 +55,7 @@ export class NzTooltipDirective implements AfterViewInit {
this.renderer.listen(this.elementRef.nativeElement, 'mouseenter', () => this.showSmoothly());
this.renderer.listen(this.elementRef.nativeElement, 'mouseleave', () => {
this.hideSmoothly();
if (!overlayElement) { // NOTE: we bind events under "mouseleave" due to the overlayRef is only created after the overlay was completely shown up
if (this.tooltip.overlay.overlayRef && !overlayElement) { // NOTE: we bind events under "mouseleave" due to the overlayRef is only created after the overlay was completely shown up
overlayElement = this.tooltip.overlay.overlayRef.overlayElement;
this.renderer.listen(overlayElement, 'mouseenter', () => this.showSmoothly());
this.renderer.listen(overlayElement, 'mouseleave', () => this.hideSmoothly());
Expand Down

0 comments on commit 54ff189

Please sign in to comment.