chore(navigate-away-prompt): add check if parent element contain a closed modal

This commit is contained in:
Johannes Eder 2021-11-28 15:12:42 +01:00 committed by Sarah Vaupel
parent 7dbe1ac08a
commit cceef60cb8

View File

@ -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;
}
}