Skip to content

Commit e38caf5

Browse files
edcarrollmcosta74
authored andcommitted
fix(datepicker): Fixed destroyed view errors
1 parent 2562cb8 commit e38caf5

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/modules/popup/classes/popup-component-controller.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SuiComponentFactory } from "../../../misc/util/index";
33
import { SuiPopupController } from "./popup-controller";
44
import { PopupConfig } from "./popup-config";
55

6-
export class SuiPopupComponentController<T> extends SuiPopupController implements OnDestroy {
6+
export class SuiPopupComponentController<T> extends SuiPopupController {
77
// Stores reference to generated content component.
88
private _contentComponentRef?:ComponentRef<T>;
99

@@ -20,13 +20,6 @@ export class SuiPopupComponentController<T> extends SuiPopupController implement
2020
config:PopupConfig) {
2121

2222
super(renderer, element, componentFactory, config);
23-
24-
this.popup.onClose.subscribe(() => {
25-
if (this._contentComponentRef) {
26-
this._contentComponentRef.destroy();
27-
this._contentComponentRef = undefined;
28-
}
29-
});
3023
}
3124

3225
public open():void {
@@ -38,11 +31,12 @@ export class SuiPopupComponentController<T> extends SuiPopupController implement
3831
super.open();
3932
}
4033

41-
public ngOnDestroy():void {
34+
protected cleanup():void {
35+
super.cleanup();
36+
4237
if (this._contentComponentRef) {
4338
this._contentComponentRef.destroy();
39+
this._contentComponentRef = undefined;
4440
}
45-
46-
super.ngOnDestroy();
4741
}
4842
}

src/modules/popup/classes/popup-controller.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
3838
this.popup.config = config;
3939

4040
// When the popup is closed (onClose fires on animation complete),
41-
this.popup.onClose.subscribe(() => {
42-
this._componentRef.instance.positioningService.destroy();
43-
this._componentFactory.detachFromApplication(this._componentRef);
44-
45-
// Remove the document click handler
46-
this._documentListener();
47-
});
41+
this.popup.onClose.subscribe(() => this.cleanup());
4842
}
4943

5044
public configure(config?:IPopupConfig):void {
@@ -175,9 +169,22 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
175169
}
176170
}
177171

178-
public ngOnDestroy():void {
172+
protected cleanup():void {
179173
clearTimeout(this._openingTimeout);
174+
175+
if (this._componentRef.instance && this._componentRef.instance.positioningService) {
176+
this._componentRef.instance.positioningService.destroy();
177+
}
178+
180179
this._componentFactory.detachFromApplication(this._componentRef);
181-
this._componentRef.destroy();
180+
181+
if (this._documentListener) {
182+
// Remove the document click handler
183+
this._documentListener();
184+
}
185+
}
186+
187+
public ngOnDestroy():void {
188+
this.cleanup();
182189
}
183190
}

src/modules/popup/components/popup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class SuiPopup implements IPopup {
6767
// Keeps track of whether the popup is open internally.
6868
private _isOpen:boolean;
6969
// `setTimeout` timer pointer for cancelling popup close.
70-
private _closingTimeout:number;
70+
public closingTimeout:number;
7171

7272
// Fires when the popup opens (and the animation is completed).
7373
public onOpen:EventEmitter<void>;
@@ -140,7 +140,7 @@ export class SuiPopup implements IPopup {
140140
// Only attempt to open if currently closed.
141141
if (!this.isOpen) {
142142
// Cancel the closing timer.
143-
clearTimeout(this._closingTimeout);
143+
clearTimeout(this.closingTimeout);
144144

145145
// Cancel all other transitions, and initiate the opening transition.
146146
this.transitionController.stopAll();
@@ -183,9 +183,9 @@ export class SuiPopup implements IPopup {
183183
new Transition(this.config.transition, this.config.transitionDuration, TransitionDirection.Out));
184184

185185
// Cancel the closing timer.
186-
clearTimeout(this._closingTimeout);
186+
clearTimeout(this.closingTimeout);
187187
// Start the closing timer, that fires the `onClose` event after the transition duration number of milliseconds.
188-
this._closingTimeout = window.setTimeout(() => this.onClose.emit(), this.config.transitionDuration);
188+
this.closingTimeout = window.setTimeout(() => this.onClose.emit(), this.config.transitionDuration);
189189

190190
// Finally, set the popup to be closed.
191191
this._isOpen = false;

0 commit comments

Comments
 (0)