Skip to content

Commit 5e063c8

Browse files
Fix page scroll while dialog open
1 parent 7b41214 commit 5e063c8

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

projects/ngsuite/src/lib/dialog/services/Dialog.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,20 @@ export class NGSuiteDialog {
5757
'add "<ngs-dialog-root></ngs-dialog-root>" to your root component to enable the NGSuiteDialog feature.'
5858
);
5959

60+
const onClosed = (ins: NGSuiteDialogInstance) => {
61+
this.registry.remove(ins);
62+
}
63+
6064
const instance = new NGSuiteDialogInstance(
6165
root.viewContainerRef,
6266
component,
6367
root.injector,
68+
onClosed,
6469
config
6570
);
6671

6772
this.registry.add(instance);
6873

69-
instance.afterClosed.subscribe(() => {
70-
this.registry.remove(instance);
71-
});
72-
7374
return instance;
7475
}
7576

projects/ngsuite/src/lib/dialog/services/DialogInstance.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { NGSuiteDialogComponent } from "../components/dialog/dialog.component";
55
import { NGSuiteDialogCommand, NGSuiteDialogConfig, NGS_DIALOG_CONFIG, NGS_DIALOG_CONTENT } from "../interfaces/Dialog";
66
import { NGSuiteDialogRef } from "./DialogRef";
77

8+
type OnClosedFn = (ins: NGSuiteDialogInstance) => void;
9+
810
export class NGSuiteDialogInstance {
911

1012
private xDialogComponentRef: ComponentRef<NGSuiteDialogComponent> = null as any;
@@ -20,6 +22,7 @@ export class NGSuiteDialogInstance {
2022
private xViewContainerRef: ViewContainerRef,
2123
private component: NGSuiteComponent<any>,
2224
private injector: Injector,
25+
private onClosed: OnClosedFn,
2326
private config?: NGSuiteDialogConfig
2427
) {
2528
this.command = new Observable<NGSuiteDialogCommand<any>>(subscriber => {
@@ -78,6 +81,8 @@ export class NGSuiteDialogInstance {
7881
const { xAfterClosedSubscriber } = this;
7982
xAfterClosedSubscriber.next(data);
8083
xAfterClosedSubscriber.complete();
84+
85+
this.onClosed(this);
8186
}
8287

8388
send(cmd: NGSuiteDialogCommand<any>) {

projects/ngsuite/src/lib/dialog/services/DialogRegistry.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export class NGSuiteDialogRegistry {
3030

3131
private readonly cloneList = () => Array.from(this.list());
3232

33+
private readonly indexOf = (item: NGSuiteDialogInstance) => {
34+
const entries = this.list();
35+
return entries.indexOf(item);
36+
}
37+
3338
readonly active = () => {
3439
const entries = this.cloneList();
3540
if (!entries.length) return null;
@@ -54,7 +59,7 @@ export class NGSuiteDialogRegistry {
5459
readonly remove = (item: NGSuiteDialogInstance) => {
5560
const entries = this.cloneList();
5661

57-
const index = entries.indexOf(item);
62+
const index = this.indexOf(item);
5863
entries.splice(index, 1);
5964

6065
this.list.set(entries);

0 commit comments

Comments
 (0)