Skip to content

Commit

Permalink
* modal: fix scrollbar not restore when other element triggered show …
Browse files Browse the repository at this point in the history
…event.
  • Loading branch information
catouse committed Mar 19, 2024
1 parent 630d8f7 commit c83ac4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lib/modal/src/vanilla/modal-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,23 @@ export class ModalBase<T extends ModalBaseOptions = ModalBaseOptions> extends Co

this._observeResize();

this.on('hidden', () => {
if (!ModalBase.getAll().some((modal) => modal.shown)) {
this.on('hidden', (event) => {
const {modalElement} = this;
if (!modalElement.parentNode) {
return this.destroy();
}
if ((event.target as HTMLElement).closest('.modal') === modalElement && !ModalBase.getAll().some((modal) => modal.shown)) {
$('html').enableScroll();
}
});
this.on('show', () => {
$('html').disableScroll();
this.on('show', (event) => {
const {modalElement} = this;
if (!modalElement.parentNode) {
return this.destroy();
}
if ((event.target as HTMLElement).closest('.modal') === modalElement) {
$('html').disableScroll();
}
});
if (this.shown) {
$('html').disableScroll();
Expand Down
6 changes: 4 additions & 2 deletions lib/modal/src/vanilla/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ export class Modal<T extends ModalOptions = ModalOptions> extends ModalBase<T> {
afterInit() {
super.afterInit();
if (this.options.destoryOnHide) {
this.on('hidden', () => {
this.destroy();
this.on('hidden', (event) => {
if ((event.target as HTMLElement).closest('.modal') === this.modalElement) {
this.destroy();
}
});
}
}
Expand Down

0 comments on commit c83ac4f

Please sign in to comment.