fix: 🐛 acceptCookie and denyCookie were trying to change domElements from cookie list event if not present

This commit is contained in:
Jérémy Munsch 2024-05-28 12:13:52 +02:00
parent b78c05890e
commit 4a56bc765f
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC

View file

@ -281,10 +281,13 @@ export default class CookieNotice {
acceptCookie(cookieName: string) {
const cookieOptions = this.getCookie(cookieName);
this.setCookieStatus(cookieName, CookieStatus.true, cookieOptions);
const cnSwitch = document.getElementById(`${cookieName}-switch`) as HTMLInputElement;
const cnSwitchInput = cnSwitch!.querySelector("input") as HTMLInputElement;
cnSwitchInput!.checked = true;
cnSwitch!.ariaChecked = "true";
const cnSwitch = document.getElementById(`${cookieName}-switch`) as HTMLInputElement | null;
const cnSwitchInput = cnSwitch?.querySelector("input") as HTMLInputElement | null;
if (!cnSwitch || !cnSwitchInput) {
return;
}
cnSwitchInput.checked = true;
cnSwitch.ariaChecked = "true";
}
/**
@ -301,10 +304,13 @@ export default class CookieNotice {
denyCookie(cookieName: string) {
const cookieOptions = this.getCookie(cookieName);
this.setCookieStatus(cookieName, CookieStatus.false, cookieOptions);
const cnSwitch = document.getElementById(`${cookieName}-switch`) as HTMLInputElement;
const cnSwitchInput = cnSwitch!.querySelector("input") as HTMLInputElement;
cnSwitchInput!.checked = false;
cnSwitch!.ariaChecked = "false";
const cnSwitch = document.getElementById(`${cookieName}-switch`) as HTMLInputElement | null;
const cnSwitchInput = cnSwitch?.querySelector("input") as HTMLInputElement | null;
if (!cnSwitch || !cnSwitchInput) {
return;
}
cnSwitchInput.checked = false;
cnSwitch.ariaChecked = "false";
}
/**