Skip to content

Commit

Permalink
* modal: fix disable scrollbar not work with static modal.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Nov 1, 2023
1 parent 39b0559 commit 167a84c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/modal/src/vanilla/modal-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ export class ModalBase<T extends ModalBaseOptions = ModalBaseOptions> extends Co
}

this._observeResize();

this.on('hidden', () => {
if (!ModalBase.getAll().some((modal) => modal.shown)) {
$('html').enableScroll();
}
});
this.on('show', () => {
$('html').disableScroll();
});
if (this.shown) {
$('html').disableScroll();
}
}

destroy(): void {
Expand Down
12 changes: 4 additions & 8 deletions lib/modal/src/vanilla/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,15 @@ export class Modal<T extends ModalOptions = ModalOptions> extends ModalBase<T> {

afterInit() {
super.afterInit();
this.on('hidden', () => {
if (this.options.destoryOnHide) {
if (this.options.destoryOnHide) {
this.on('hidden', () => {
this.destroy();
}
if (!Modal.getAll().some((modal) => modal.shown)) {
$('html').enableScroll();
}
});
});
}
}

show(options?: Partial<T>) {
if (super.show(options)) {
$('html').disableScroll();
this.buildDialog();
return true;
}
Expand Down

0 comments on commit 167a84c

Please sign in to comment.