feat: per-category hidden flag for settings modal - #6
Merged
Conversation
Add categories.<id>.hidden: true config option to remove consent categories from the settings modal. Hidden categories are forced to false (rejected) in the consent state — a visitor can never accept a toggle they cannot see. Essential cannot be hidden. Also accepts data-hide-categories="analytics,marketing" data attribute (comma-separated list of category IDs) for script-tag-only setups. Changes: - src/core/categories.js: hidden flag in DEFAULT_CATEGORIES, getDefaultConsent() forces false for hidden, getHiddenCategoryIds() - src/storage/consent-store.js: setHiddenCategoryIds() setter, applyHiddenOverride() in load/save/update/acceptAll - src/core-lifecycle.js: wire setHiddenCategoryIds in coreInit, hasNonEssential now checks result.current instead of selections - src/ui/modal.js: filter hidden categories from rendering, getSelections() explicitly sets hidden categories to false - src/config/parser.js: parse data-hide-categories attribute - zest.config.schema.json: hidden property in category definition - src/types/zest.d.ts: CategoryConfig interface, categories in InitOptions - README.md: document categories config and data-hide-categories - CHANGELOG.md: unreleased entry - tests/hide-categories.test.js: 20 tests covering all paths Closes #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5.
What
Add
categories.<id>.hidden: trueto remove a consent category from the settings modal. Hidden categories are forced tofalse(rejected) in the consent state — a visitor can never accept a toggle they cannot see. Essential cannot be hidden; the flag is ignored for it.Why
Sites that only use 1-2 consent categories currently show all four toggles in the settings modal. Empty toggles for categories the site does not use are confusing and arguably misleading (they imply data processing that is not happening). See #5 for the original request.
How
categories.analytics.hidden: trueinwindow.ZestConfig(JS config)data-hide-categories="analytics,marketing"on the script tag (data attribute)window.ZestConfig.categoriessurvives whendata-hide-categoriesis also setHidden categories are forced to
falsein every consent path:loadConsent,updateConsent,acceptAll,saveConsent. The modal filters them from rendering.getSelections()explicitly sets them tofalsesoupdateConsentreceives a complete consent object.Files
src/core/categories.js—hidden: falsein defaults,getDefaultConsent()forces false,getHiddenCategoryIds()src/storage/consent-store.js—setHiddenCategoryIds(),applyHiddenOverride()in all consent write pathssrc/core-lifecycle.js— wiresetHiddenCategoryIdsincoreInit,hasNonEssentialnow checksresult.currentsrc/ui/modal.js— filter hidden from render,getSelections()sets hidden to falsesrc/config/parser.js— parsedata-hide-categories, deep-merge categories from window + data sourceszest.config.schema.json—hiddenin category definitionsrc/types/zest.d.ts—CategoryConfiginterface,categoriesinInitOptionsREADME.md— document both config and data attributeCHANGELOG.md— unreleased entrytests/hide-categories.test.js— 21 testsTests
98 pass, build OK. Lint is pre-existing broken on main (ESLint v10 config migration).