-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Describe the bug
When clicking "Reject All", optional cookie categories that were previously accepted (or manually ticked) remain enabled. The button doesn't actually uncheck them before saving the consent settings.
To Reproduce
Prerequisites: Have at least one optional cookie category configured (e.g. analytics, marketing, performance).
- Clear all cookies for the site
- Open the cookie consent banner
- Click "Accept All" — optional categories are now enabled
- Re-open the cookie consent banner
- Click "Reject All"
- Check the cookie value — optional categories are still
true
Expected behavior
Clicking "Reject All" should set all optional categories to false, leaving only strictly_necessary as true.
Additional context
The issue is in resources/js/scripts.js. The handleRejectOptionalCookies() function (lines 232-234) calls getConsentSettings(false, "strictly_necessary"):
// lines 232-234
function handleRejectOptionalCookies() {
handleCookieConsent(getConsentSettings(false, "strictly_necessary"));
}
// lines 236-242
function getConsentSettings(acceptAll = false, requiredCategory = null) {
const consent = {};
document.querySelectorAll(".cookie-category").forEach((checkbox) => {
consent[checkbox.id] = acceptAll || checkbox.id === requiredCategory || checkbox.checked;
});
return consent;
}The problem is || checkbox.checked at the end of line 239. When rejecting:
acceptAllisfalsecheckbox.id === requiredCategoryisfalsefor optional categories (onlytrueforstrictly_necessary)checkbox.checkedistrue(checkbox was ticked previously)
So false || false || true evaluates to true, and the optional category remains enabled.
A simple fix would be to uncheck all optional checkboxes before building the consent object:
function handleRejectOptionalCookies() {
document.querySelectorAll(".cookie-category").forEach((checkbox) => {
if (checkbox.id !== "strictly_necessary") {
checkbox.checked = false;
}
});
handleCookieConsent(getConsentSettings(false, "strictly_necessary"));
}