From 998da390acf13100d6eb539865f34bbab54c9155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 29 May 2024 11:15:48 +0200 Subject: [PATCH] fix: :bug: Cookie Modal list 'toggleCookie' was using wrong HTMLElement --- src/ts/index.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/ts/index.ts b/src/ts/index.ts index e8cea5c..ded685a 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -748,29 +748,21 @@ export default class CookieNotice { cnSwitch.setAttribute("aria-labelledby", `${cookieName}-desc`); cnSwitch.setAttribute("aria-describedby", `${cookieName}-desc`); - const toggleCookie = () => { + const toggleCookie = (activate:boolean) => { this.setCookieStatus( cookieName, - cnSwitch.checked ? CookieStatus.true : CookieStatus.false, + activate ? CookieStatus.true : CookieStatus.false, cookieConfig ); }; this.addEvent(cnSwitch, "click", () => { - toggleCookie(); - if (cnSwitchInput.checked) { - cnSwitch.ariaChecked = "true"; - } else { - cnSwitch.ariaChecked = "false"; - } + toggleCookie(cnSwitchInput.checked); + cnSwitch.ariaChecked = cnSwitchInput.checked ? "true" : "false"; }); this.addEventKbdValidate(cnSwitch, () => { - toggleCookie(); + toggleCookie(cnSwitchInput.checked); cnSwitchInput.checked = !cnSwitchInput.checked; - if (cnSwitchInput.checked) { - cnSwitch.ariaChecked = "true"; - } else { - cnSwitch.ariaChecked = "false"; - } + cnSwitch.ariaChecked = cnSwitchInput.checked ? "true" : "false"; }); this.cookiesUnorderedList.append(cookie);