Skip to content

Commit

Permalink
fix(module:tooltip): fix tooltip accessing destroyed view
Browse files Browse the repository at this point in the history
close NG-ZORRO#3875
close NG-ZORRO#4317
close NG-ZORRO#4386

feat(module:tooltip,popover,popconfirm): remove component usage"

test: refactor tests and remove specs related to component api

refactor: remove redundant code

fix: fix property accessibility

refactor: extract isEmpty function

chore: start warning of deprecated API

chore: cleanup
  • Loading branch information
Wendell committed Nov 8, 2019
1 parent 09f1ec6 commit 8d0d051
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 871 deletions.
42 changes: 21 additions & 21 deletions components/popconfirm/nz-popconfirm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Host,
Input,
Optional,
Output,
TemplateRef,
ViewEncapsulation
} from '@angular/core';

import { zoomBigMotion, InputBoolean, NzNoAnimationDirective } from 'ng-zorro-antd/core';
import { NzTooltipBaseComponentLegacy, NzTooltipTrigger, NzToolTipComponent } from 'ng-zorro-antd/tooltip';
import { zoomBigMotion, NzNoAnimationDirective } from 'ng-zorro-antd/core';
import { NzTooltipTrigger, NzToolTipComponent } from 'ng-zorro-antd/tooltip';
import { Subject } from 'rxjs';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -30,12 +28,6 @@ import { NzTooltipBaseComponentLegacy, NzTooltipTrigger, NzToolTipComponent } fr
preserveWhitespaces: false,
animations: [zoomBigMotion],
templateUrl: './nz-popconfirm.component.html',
providers: [
{
provide: NzTooltipBaseComponentLegacy,
useExisting: NzPopconfirmComponent
}
],
styles: [
`
.ant-popover {
Expand All @@ -45,23 +37,31 @@ import { NzTooltipBaseComponentLegacy, NzTooltipTrigger, NzToolTipComponent } fr
]
})
export class NzPopconfirmComponent extends NzToolTipComponent {
@Input() nzOkText: string;
@Input() nzOkType: string = 'primary';
@Input() nzCancelText: string;
@Input() @InputBoolean() nzCondition = false;
@Input() nzIcon: string | TemplateRef<void>;
nzCancelText: string;
nzCondition = false;
nzIcon: string | TemplateRef<void>;
nzOkText: string;
nzOkType: string = 'primary';

readonly nzOnCancel = new Subject<void>();
readonly nzOnConfirm = new Subject<void>();

@Output() readonly nzOnCancel: EventEmitter<void> = new EventEmitter();
@Output() readonly nzOnConfirm: EventEmitter<void> = new EventEmitter();
protected _trigger: NzTooltipTrigger = 'click';

_prefix = 'ant-popover-placement';
_trigger: NzTooltipTrigger = 'click';
_hasBackdrop = true;

constructor(cdr: ChangeDetectorRef, @Host() @Optional() public noAnimation?: NzNoAnimationDirective) {
super(cdr, noAnimation);
}

dispose(): void {
super.dispose();

this.nzOnCancel.complete();
this.nzOnConfirm.complete();
}

show(): void {
if (!this.nzCondition) {
super.show();
Expand All @@ -71,12 +71,12 @@ export class NzPopconfirmComponent extends NzToolTipComponent {
}

onCancel(): void {
this.nzOnCancel.emit();
this.nzOnCancel.next();
super.hide();
}

onConfirm(): void {
this.nzOnConfirm.emit();
this.nzOnConfirm.next();
super.hide();
}
}
13 changes: 6 additions & 7 deletions components/popconfirm/nz-popconfirm.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export class NzPopconfirmDirective extends NzTooltipBaseDirective implements OnI
@Output() readonly nzOnCancel = new EventEmitter<void>();
@Output() readonly nzOnConfirm = new EventEmitter<void>();

componentFactory: ComponentFactory<NzPopconfirmComponent> = this.resolver.resolveComponentFactory(
protected readonly componentFactory: ComponentFactory<NzPopconfirmComponent> = this.resolver.resolveComponentFactory(
NzPopconfirmComponent
);

protected needProxyProperties = [
protected readonly needProxyProperties = [
'nzOverlayClassName',
'nzOverlayStyle',
'nzMouseEnterDelay',
Expand All @@ -78,17 +78,16 @@ export class NzPopconfirmDirective extends NzTooltipBaseDirective implements OnI
hostView: ViewContainerRef,
resolver: ComponentFactoryResolver,
renderer: Renderer2,
@Optional() tooltip: NzPopconfirmComponent,
@Host() @Optional() public noAnimation?: NzNoAnimationDirective
@Host() @Optional() noAnimation?: NzNoAnimationDirective
) {
super(elementRef, hostView, resolver, renderer, tooltip, noAnimation);
super(elementRef, hostView, resolver, renderer, noAnimation);
}

/**
* @override
*/
protected createDynamicTooltipComponent(): void {
super.createDynamicTooltipComponent();
protected createTooltipComponent(): void {
super.createTooltipComponent();

(this.tooltip as NzPopconfirmComponent).nzOnCancel.pipe(takeUntil(this.$destroy)).subscribe(() => {
this.nzOnCancel.emit();
Expand Down
Loading

0 comments on commit 8d0d051

Please sign in to comment.