INSR-8881: Ensure modal links don't end up with doubled listeners

This commit is contained in:
Alex Humphries 2026-04-17 10:36:26 -04:00
parent 1836e6c83f
commit 9fd92eb4cd
2 changed files with 9 additions and 7 deletions

View file

@ -526,13 +526,13 @@ export function doesCopyContainTextLink(copy) {
* *
* @param context * @param context
*/ */
export function setupModalLinks(context) { export function setupModalLinks(context, abortSignal = null) {
context.$nextTick(() => { context.$nextTick(() => {
const elements = document.getElementsByClassName('modal-text'); const elements = document.getElementsByClassName('modal-text');
for (const element of elements) { for (const element of elements) {
const target = element.getAttribute('modalTarget'); const target = element.getAttribute('modalTarget');
if (target) { if (target) {
element.addEventListener('click', () => context.$refs[target].openModal()); element.addEventListener('click', () => context.$refs[target].openModal(), { signal: abortSignal });
} }
} }
}); });
@ -547,6 +547,7 @@ export function setupModalLink(context, desiredTarget) {
context.$nextTick(() => { context.$nextTick(() => {
const element = document.querySelector(`[modalTarget=${desiredTarget}]`); const element = document.querySelector(`[modalTarget=${desiredTarget}]`);
if (element) { if (element) {
element.removeEventListener('click', () => context.$refs[desiredTarget].openModal());
element.addEventListener('click', () => context.$refs[desiredTarget].openModal()); element.addEventListener('click', () => context.$refs[desiredTarget].openModal());
} }
}); });

View file

@ -131,7 +131,6 @@ import recalModal from '@/iss-components/recal-modal/recal-modal.vue';
// Import Supporting Files // Import Supporting Files
import { import {
fetchCmsContentForPage, fetchCmsContentForPage,
setupModalLink,
setupModalLinks, setupModalLinks,
processIfStatements processIfStatements
} from '@/helpers/cms-content-helper.js'; } from '@/helpers/cms-content-helper.js';
@ -231,7 +230,8 @@ export default {
}, },
RECAL_MODAL_REF_NAME, RECAL_MODAL_REF_NAME,
CANCEL_CLAIM_REF_NAME, CANCEL_CLAIM_REF_NAME,
OEM_ENDORSEMENT_REF_NAME OEM_ENDORSEMENT_REF_NAME,
abortController: new AbortController()
}; };
}, },
computed: { computed: {
@ -367,8 +367,9 @@ export default {
watch: { watch: {
nextStepsBody(newValue, oldValue) { nextStepsBody(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
setupModalLink(this, RECAL_MODAL_REF_NAME); this.abortController.abort();
setupModalLink(this, OEM_ENDORSEMENT_REF_NAME); this.abortController = new AbortController();
setupModalLinks(this, this.abortController.signal);
} }
} }
}, },
@ -376,7 +377,7 @@ export default {
if (this.isPageLoading) { if (this.isPageLoading) {
showIssLoadingModal(true); showIssLoadingModal(true);
} }
setupModalLinks(this); setupModalLinks(this, this.abortController.signal);
}, },
methods: { methods: {
logEventsToGA() { logEventsToGA() {