Skip to content

Respect prefers-reduced-motion #285

Open

Description

@joshunrau
No description provided.

Activity

  1. added
    Priority: Low
    Enhancement
    and removed on May 3, 2023
  2. changed the title [-]Respect prefers-reduced-motion[/-] [+][Enhancement]: Respect prefers-reduced-motion[/+] on May 8, 2023
  3. added
    Difficulty: Medium
    on Sep 27, 2026
  4. changed the title [-][Enhancement]: Respect prefers-reduced-motion[/-] [+]Respect prefers-reduced-motion[/+] on Sep 27, 2026
  5. added
    Area: Web
    Area: Shared
    on Sep 27, 2026
  6. joshunrau commented on Oct 26, 2026

    @joshunrau
    CollaboratorAuthor

    Still unimplemented on main (d86740e). Nothing in apps/web, apps/gateway, apps/playground or packages/react-core reads prefers-reduced-motion. The only match is the Interactive-With-React example instrument's App.css.

    What animates, and what reaches it

    1. motion/react 13.4.4 in app code. InstrumentShowcase.tsx:129-136 (cards rise 80 px on a 1.5 s spring), WalkthroughProvider.tsx:463-467 (the popover glides to each target), start-session.tsx:65-71 (scale 0.5 to 1), ToggledContent.tsx:25-28 (height), the playground Editor.tsx:88-91 (sidebar width), and the layout lists in dashboard.tsx and admin/instrument-repos/index.tsx. <MotionConfig reducedMotion="user"> covers all of these. In motion-dom 13.4.4 it makes transforms, width/height/top/left/right/bottom and layout animations instant, and keeps opacity fades.
    2. CSS. libui's Dialog, Popover, Select, DropdownMenu and Tooltip use tw-animate-css zoom-in-95/slide-in-from-*, and the mobile nav Sheet (Navbar.tsx:39) slides in from the right over 500 ms. tw-animate-css 1.4.0 has no reduced-motion rule. The hover scales at dashboard.tsx:165,172,229,240,251,258,327,334 and InstrumentCard.tsx:139 are plain Tailwind. MotionConfig reaches none of this.
    3. libui's own motion components. libui 6.16.1 depends on motion ^11.18.2, which pnpm resolves to a separate motion@11.18.2 copy. That copy has its own React context, so an app-level MotionConfig does not reach NotificationHub, DatePicker/Calendar (x/y slides) or the password strength bar.
    4. Explicit smooth scrolling. scrollIntoView({ behavior: 'smooth' }) at InstrumentShowcase.tsx:65 and GroupEmailTemplates/CreateTemplateForm.tsx:38. Neither MotionConfig nor a stylesheet overrides an explicit behavior.

    There is a trap in 3. NotificationHub dismisses each toast in onAnimationComplete of a width 0% to 100% bar timed to the timeout. Under reduced motion width jumps straight to 100%, so every toast would vanish as it appears. libui 6.18.0, the latest release, still does this. libui has to move dismissal onto a timer before it puts MotionConfig in CoreProvider.

    These need nothing. useSpring (UploadProgressBar.tsx:12, libui StatisticCard) ignores MotionConfig, but it only smooths a number or a bar. Interactive instruments run in their own iframe (InteractiveContent.tsx:175) without the host's CSS, so none of this changes a task's stimulus timing. The recharts <Area>/<Line> draw-in (1.5 s) ignores the setting in recharts 2.15.4, but recharts 3.10.1, which #1660 brings in, defaults isAnimationActive to 'auto' and skips the animation under reduced motion.

    Plan

    1. In react-core, add a MotionPreferenceProvider (<MotionConfig reducedMotion="user">) and export it from src/index.ts. Render it inside CoreProvider in apps/web/src/routes/__root.tsx, apps/gateway/src/Root.tsx, apps/playground/src/App.tsx and apps/playground/src/preview/main.tsx; the preview frame is a separate React root. Because it lives in react-core, the gateway needs no direct motion dependency. Placing it inside CoreProvider also keeps NotificationHub outside it if libui ever shares the app's motion copy.
    2. In packages/react-core/src/globals.css, add an unlayered @media (prefers-reduced-motion: reduce) block that resets --tw-enter-translate-x/-y, --tw-enter-scale, --tw-enter-rotate and their --tw-exit-* counterparts to identity on *, ::before, ::after. Unlayered rules beat Tailwind's utilities layer, so this overrides the libui classes while the fades still run. Avoid the usual animation-duration: 0.01ms !important reset: it would freeze animate-spin and libui's animate-spinner, which are the only loading signal. Rewrite the "three directives" line in packages/react-core/AGENTS.md in the same commit; the color-scheme rules already made it stale.
    3. Prefix the hover scales listed above with motion-safe:.
    4. Pass behavior: useReducedMotionConfig() ? 'auto' : 'smooth' to both scrollIntoView calls. That hook reads the provider, so the preference stays in one place.
    5. Upstream in libui: timer-based dismissal, then MotionConfig in CoreProvider. Steps 1-4 do not wait on this.

    I would follow the OS setting only. An in-app toggle could come later through the same provider.

    Tests

    • Unit: packages/react-core/src/components/MotionPreferenceProvider/__tests__/MotionPreferenceProvider.test.tsx renders a probe that reads useContext(MotionConfigContext).reducedMotion and expects 'user'. Do not assert through an animation: motion caches the media query in a module singleton on first mount, and the shared skipAnimations setup file Upgrade happy-dom past 20.11, whose Element.animate leaks unhandled rejections #1621 proposes would make everything instant anyway. Extend apps/web/src/routes/__tests__/__root.test.tsx and apps/gateway/src/__tests__/Root.test.tsx with the same probe. In InstrumentShowcase.test.tsx and CreateTemplateForm.test.tsx, render under <MotionConfig reducedMotion="always"> and expect scrollIntoView to receive behavior: 'auto'.
    • e2e: a new testing/src/specs/reduced-motion.spec.ts with test.use({ reducedMotion: 'reduce' }).
      • On /instruments/accessible-instruments, li[data-instrument-index="2"] reaches transform: none within a 250 ms toHaveCSS timeout. Without the fix, its 0.3 s delay and 1.5 s spring keep it offset well past that.
      • The dashboard users dialog (dashboard-users-Modal-dialog) has --tw-enter-scale of 1.
      • A no-preference case for the same dialog shows that the reset only applies under the media query.

    #1819 edits only the trend chart legend in dashboard.tsx, so it does not conflict. #1810 edits CreateTemplateForm.tsx close to the scrollIntoView call, so land step 4 after it. No other open PR touches these files.

    Triage note written with Claude Code. Code references point at main @ d86740e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SharedArea: WebDifficulty: MediumEnhancementPriority: Low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions