ConsentPreferencesDialog
Granular consent preferences: one Switch per category, draft state re-seeded from the stored decision on open, saved via consent.set. Required categories render checked and disabled. Must be used inside ConsentProvider.
Design intent
GDPR-style consent requires letting visitors adjust each category after an initial choice. The dialog owns the per-category editing UX (draft state re-seeded on open, required categories locked) while ConsentProvider owns persistence, so reopening always reflects the stored decision.
npx @slipstream-ui/cli@latest add consent-preferences-dialogWe use cookies
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | required | Whether the dialog is visible. |
| onOpenChange | (open: boolean) => void | required | Open/close requests from Escape, backdrop, Cancel or Save. |
| categories | readonly ConsentCategory[] | required | Toggle categories; ids must match the provider purposes. |
| title | string | 'Cookie preferences' | Dialog heading. |
| description | string | — | Helper text under the title. |
| saveLabel | ReactNode | 'Save preferences' | Save button label. |
Anti-patterns
validate_usage is the MCP tool that rejects these mistakes: the same list agents see over MCP and in the canonical markdown.
Don't use category ids the provider doesn't know
consent.set only persists purposes declared on ConsentProvider; unknown ids are dropped silently. Keep categories and purposes in sync.
tsx// Avoidpurposes={['analytics']} + categories={[{ id: 'marketing', ... }]}// PreferShare one constant: const PURPOSES = ['analytics', 'marketing'] as const;Don't make every category required
Required categories render checked and disabled — marking optional tracking as required is a dark pattern and likely unlawful under GDPR/ePrivacy.
tsx// Avoid{ id: 'analytics', label: 'Analytics', required: true }// PreferReserve required for strictly necessary storage.
Accessibility
- Built on Dialog: role=dialog, labelled title/description, focus trap, Escape and backdrop close.
- Each Switch is aria-labelledby its category label; required categories are disabled.
- Changes are draft-only until Save — Cancel discards them.
Composition
Compose with ConsentProvider: Must be inside the provider; reads and writes the shared decision via useConsentContext
<ConsentProvider purposes={PURPOSE_IDS}>...<ConsentPreferencesDialog .../></ConsentProvider>
Compose with ConsentBanner: The banner's manage action typically opens this dialog
<ConsentBanner onManage={() => setPrefsOpen(true)} ... />
Compose with Switch: Renders each category toggle with role=switch and aria-checked
<Switch checked={draft[id]} onCheckedChange={...} aria-labelledby={...} />
Related components: ConsentProvider, ConsentBanner, Dialog, Switch
Dependencies
What the registry installs alongside this component. Package imports already include these.
npm packages
- class-variance-authority
- clsx
- tailwind-merge
Browser support
| Browser | Tested versions |
|---|---|
| Chrome | 111+ (Mar 2023) |
| Edge | 111+ (Mar 2023) |
| Firefox | 121+ (Dec 2023) |
| Safari | 17.2+: macOS & iOS (Dec 2023) |
Slipstream components rely only on CSS custom properties, Flexbox/Grid, and ARIA, the everyday baseline of the last two years of evergreen releases. Anything newer is progressive enhancement: unsupported browsers keep full functionality with static behavior instead of animations.