chore(navigate-away-prompt): add check if parent element contain a closed modal
This commit is contained in:
parent
7dbe1ac08a
commit
cceef60cb8
@ -107,7 +107,7 @@ export class NavigateAwayPrompt {
|
||||
// allow the event to happen if the form was not touched by the
|
||||
// user (i.e. if the current FormData is equal to the initial FormData)
|
||||
// or the unload event was initiated by a form submit
|
||||
if (!formDataHasChanged || this.unloadDueToSubmit)
|
||||
if (!formDataHasChanged || this.unloadDueToSubmit || this._parentModalIsClosed())
|
||||
return;
|
||||
|
||||
// cancel the unload event. This is the standard to force the prompt to appear.
|
||||
@ -117,4 +117,13 @@ export class NavigateAwayPrompt {
|
||||
// for all non standard compliant browsers we return a truthy value to activate the prompt.
|
||||
return true;
|
||||
}
|
||||
|
||||
_parentModalIsClosed() {
|
||||
const parentModal = this._element.closest('.modal');
|
||||
if (!parentModal)
|
||||
return false;
|
||||
|
||||
const modalClosed = !parentModal.classList.contains('modal--open');
|
||||
return modalClosed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user