Skip to content

ReducedMotionToggle

SM · 950B gzip budget

An in-page opt-in to reduced motion, for people who never touch OS settings.

Category
Accessibility & preferences
Budget
sm, single-purpose control
External runtime
React / React DOM only
axe fixtureSSR rendersource scanbundle budget

Preview

Live fixture
Preview locale

Try the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.

Install

npx shadcn@latest add https://gear5-ui.vercel.app/r/reduced-motion-toggle.json

Copies the source into your project. Pulls in 3 shared registry items: switch, cn, use-stored-value.

New here? Set up Tailwind and import aliases first →

Source & props

Edit on GitHub ↗

Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.

"use client";

import { useEffect } from "react";
import { useStoredValue } from "../lib/use-stored-value";
import { Switch } from "./switch";

const STORAGE_KEY = "gear5-ui:reduce-motion";

/**
 * Lets someone opt into reduced motion from inside the page, for the many
 * people who have never touched their OS accessibility settings but still
 * find animation distracting or nausea-inducing. Setting this data attribute
 * is a contract: consuming CSS should treat `[data-reduce-motion="true"]` the
 * same as `prefers-reduced-motion: reduce`.
 */
export function ReducedMotionToggle({ label = "Reduce motion" }: { label?: string }) {
  const [stored, setStored] = useStoredValue(STORAGE_KEY, "false");
  const reduced = stored === "true";

  useEffect(() => {
    document.documentElement.dataset.reduceMotion = String(reduced);
  }, [reduced]);

  return <Switch checked={reduced} onCheckedChange={(v) => setStored(String(v))} label={label} />;
}

What CI checks

Quality contract
  • Bundled, minified and gzipped against its tier budget
  • Audited by axe in the state previewed above
  • Rendered through react-dom/server with no browser globals
  • Scanned for network calls, dangerous sinks, and unguarded animation