Skip to main content
cngx-src documentation

withPersistence

Functioncore/themingv0.1.0

projects/core/theming/a11y-preferences.ts

Description#

Persist explicit accessibility choices via CNGX_A11Y_STORAGE (browser localStorage by default) under storageKey and rehydrate them on the next load. On startup a stored value overrides an axis only when it is a known-valid member of that axis' union; an unknown, invalid, or missing value leaves the axis at its own default, so a motion/contrast auto stays OS-driven and is never clobbered. The write-back skips the initial flush, so an untouched default is never written and a rehydrated value is not re-written (it is already in storage); only a later change (a user pick) is persisted. The whole feature is browser-guarded via DOCUMENT.defaultView and is a no-op on the server.

bootstrapApplication(AppComponent, {
  providers: [provideA11yPreferences(withPersistence())],
});

Signature#

withPersistence(storageKey: string)

Parameters#

@paramstorageKeystring= 'cngx-a11y'

Returns#

CngxA11yPrefFeature