DEV Community

Cover image for Rive Accessibility in React: Reduced Motion, Screen Readers and Keyboard Focus
Maxim Tincu – Rive Animator
Maxim Tincu – Rive Animator

Posted on Edited on

Rive Accessibility in React: Reduced Motion, Screen Readers and Keyboard Focus

Rive accessibility used to be a short conversation: a < canvas > is a black box to assistive technology, so you added an aria-label, maybe paused the animation, and hoped for the best. That has changed. Rive now has three accessibility features you can actually build with: reduced motion driven by Data Binding, semantics that expose real roles to screen readers, and focus so keyboard users can move through your graphic.

In this post I'll walk through all three in a React app, using only APIs from the current official Rive docs. If you're a developer receiving a .riv file, or a designer preparing one, this is the checklist I'd want both sides to follow.

Why Rive accessibility needs extra work

A Rive graphic renders into a < canvas >. Screen readers can't see what's drawn there, and the canvas doesn't know whether the user has asked their OS to reduce motion. Rive's docs are clear that none of this happens automatically:

  • Rive does not apply reduced motion for you. The file author decides which motion is essential, which is decorative, and what the reduced-motion version looks like.

  • Semantics are opt-in at runtime. The default mode is disabled, and elements with no semantics set in the editor are never exposed to screen readers.

  • Focus nodes have to be set up in the editor. The runtime connects them to the keyboard, but it doesn't draw a focus ring for you.

So accessibility in Rive is a shared job. Part of it lives in the .riv file, part of it lives in your React code. Let's go piece by piece.

Part 1: Reduced motion with Data Binding

The current recommendation from Rive is simple: detect the user's preference in your app, then pass it into the file through a Data Binding property, for example a Boolean called prefersReducedMotion. Note that this is a View Model property, not a state machine input (inputs are deprecated in favour of Data Binding).

What happens inside the Rive file

On the design side, Rive's docs suggest a few strategies. Pick the one that fits each piece of motion:

  • A separate reduced-motion path. For complex or decorative motion, build two paths in the state machine and use prefersReducedMotion in the transition conditions to choose between them.

  • Bind the speed. For simpler cases, bind a timeline or nested artboard speed to the property. Rive's docs show a converter group (Toggle, then Convert to Number) so that true becomes a speed of 0.

  • Swap motion for non-motion feedback. Reduced motion doesn't mean no feedback. Instead of bounce, scale or rotation, change opacity or color.

  • Reduce distance. Large movement can be uncomfortable even when slow. A small offset plus a fade often does the same job.

Before animating, it's worth agreeing with the team which animations carry meaning (a success state, a loading indicator) and which are pure decoration (an idle loop, a background wiggle). That one conversation decides the whole reduced-motion design.

Reading the preference in React

On the web, the user's setting comes from the prefers-reduced-motion media query. Here's a small hook that also listens for changes:

import { useEffect, useState } from "react";

const QUERY = "(prefers-reduced-motion: reduce)";

export function usePrefersReducedMotion() {
  const [reduced, setReduced] = useState(
    () => typeof window !== "undefined" && window.matchMedia(QUERY).matches
  );

  useEffect(() => {
    const mq = window.matchMedia(QUERY);
    const onChange = (e) => setReduced(e.matches);
    mq.addEventListener("change", onChange);
    return () => mq.removeEventListener("change", onChange);
  }, []);

  return reduced;
}
Enter fullscreen mode Exit fullscreen mode

Passing it into Rive before the first frame

There's one detail in the Rive React docs that matters a lot here. The Data Binding hooks (useViewModel, useViewModelInstance and friends) run after Rive has loaded, which means the first frame has already rendered by the time they bind. For most properties that's fine. For reduced motion it isn't: a user who asked for less motion could still see the opening of the full animation.

The docs recommend doing pre-render setup in the onRiveReady callback of useRive, which fires before the state machine advances. So I set the initial value there, keep a reference to the instance, and update it later if the user changes their OS setting:

import { useEffect, useRef } from "react";
import { useRive } from "@rive-app/react-canvas";
import { usePrefersReducedMotion } from "./usePrefersReducedMotion";

export default function HeroAnimation() {
  const prefersReducedMotion = usePrefersReducedMotion();
  const vmiRef = useRef(null);

  const { RiveComponent } = useRive({
    src: "/hero.riv",
    stateMachine: "State Machine 1",
    autoplay: true,
    autoBind: false, // we bind manually so the value is set before frame one
    onRiveReady: (rive) => {
      const vm = rive.viewModelByName("Hero");
      const vmi = vm.defaultInstance();

      vmi.boolean("prefersReducedMotion").value =
        window.matchMedia("(prefers-reduced-motion: reduce)").matches;

      rive.setViewModelInstance(vmi);
      rive.bind();
      vmiRef.current = vmi;
    },
  });

  // Keep Rive in sync if the user changes the setting while the page is open
  useEffect(() => {
    if (vmiRef.current) {
      vmiRef.current.boolean("prefersReducedMotion").value = prefersReducedMotion;
    }
  }, [prefersReducedMotion]);

  return <RiveComponent />;
}
Enter fullscreen mode Exit fullscreen mode

Replace "Hero" with the name of the View Model in your file. If you don't care about the first frame (for example, the graphic starts static and only moves on interaction), the simpler route is autoBind: true plus the useViewModelInstanceBoolean hook on rive?.viewModelInstance.

To test it, turn on "Reduce motion" in your OS settings, or use the rendering emulation panel in your browser's devtools to simulate prefers-reduced-motion.

Part 2: Rive semantics for screen readers

This is the big one. In the Rive Editor you can now select an element and add semantics in the Semantics panel: a role (button, checkbox, switch, slider, tab, image, list, dialog and more), a label, traits and states (selected, checked, expanded), and properties like hint and value. Text elements infer their role and label from their content automatically.

At runtime on the web, Rive builds an invisible DOM tree next to the canvas. Each semantic node becomes a real element with the matching ARIA role and attributes, positioned over the drawn graphic. A Rive "Button" becomes role="button", a "Slider" becomes role="slider" with aria-valuenow, the label becomes aria-label, and so on.

Enabling semantics in React

Semantics are off by default. Turn them on with semanticsMode, and give the whole graphic a name with riveCanvasLabel so screen reader users know what they're entering:

import { useRive, SemanticMode } from "@rive-app/react-canvas";

export default function LoginAnimation() {
  const { RiveComponent } = useRive({
    src: "/login.riv",
    stateMachine: "State Machine 1",
    autoplay: true,
    autoBind: true,
    semanticsMode: SemanticMode.Enabled,
    semanticsOptions: {
      riveCanvasLabel: "Login experience",
    },
  });

  return <RiveComponent className="rive-container" />;
}
Enter fullscreen mode Exit fullscreen mode
.rive-container {
  position: relative;
  width: 100%;
  height: 100%;
}
Enter fullscreen mode Exit fullscreen mode

That position: relative isn't decoration. The semantic overlay positions itself against the nearest positioned ancestor of the canvas. The RiveComponent wrapper isn't positioned by default, so without it the overlay can end up offset from the graphic.

Two notes from the docs worth knowing before you ship:

  • semanticsMode and semanticsOptions are marked experimental, so behaviour can change without a major version bump. Pin your runtime version and re-test after upgrades.

  • Check the Feature Support page in the Rive docs for which runtimes support semantics. Besides web and React, there are semantics pages for Flutter, React Native and Apple.

What the designer has to do

Semantics only work if they're in the file. Before a .riv with semantics gets handed off, these are the things worth checking:

  • Every meaningful image has a label. An image with no label is treated as decorative and hidden from assistive tech.

  • States are bound, not guessed. Bind a View Model Boolean to a switch's toggled state, and a slider's value to the semantic value, so what's announced matches what's on screen.

  • Semantic Tap is handled. Add a Semantic Action listener (Tap) next to your Click listener, so screen reader activation does the same thing as a pointer click. Sliders also need Increase and Decrease.

  • Hidden really means hidden. Elements hidden by layout or solos are removed automatically. An element that's still in the scene at 0% opacity needs the Hidden state.

  • Live regions for dynamic text. If a score or status changes, mark it as a live region so it gets announced.

Part 3: Keyboard focus

The third piece is focus. Designers can mark elements as focus nodes in the editor and set their order. When the playing state machine has focus nodes, the React runtime makes the canvas a single tab stop and routes keys inside it:

  • Tab / Shift + Tab moves to the next or previous focus node.

  • Arrow keys move to the nearest focus node in that direction.

  • Tabbing past the last node releases focus back to the page, unless the designer set the nodes to wrap.

You don't need any extra code for the default behaviour. A few options exist for specific cases:

  • tabIndex: -1 keeps the canvas out of the page tab order (reachable by click only).

  • focusOptions: { allowFocusInterrupt: true } lets the graphic pull browser focus to itself. Rive's docs warn this can be jarring, so keep it for full-page experiences like menus or game UI.

  • rive.clearFocus() clears focus inside the graphic, for example when you close a Rive-powered menu. It doesn't move browser focus, so focus the next element yourself.

The runtime doesn't draw a focus indicator. That's a design task: every focus node needs a visible focused state in the file. If you're briefing an animator, put "focus states for every interactive element" in the brief from day one.

A quick testing checklist

Before you call a Rive graphic accessible, run through this:

  • Turn on Reduce Motion in your OS and reload. Nothing decorative should move on the first frame.

  • Turn on a screen reader (VoiceOver on macOS and iOS, TalkBack on Android, Narrator or NVDA on Windows) and step through the graphic. Check labels, roles, values, states and order.

  • Open devtools and look for the rive-a11y-... element right after your canvas, or inspect the browser's accessibility tree.

  • Tab through the page with a keyboard only. Can you enter, use and leave the graphic, and can you always see where focus is?

Need a Rive animator?

I'm Maxim, a Rive animator and motion designer with 10+ years in motion and 100+ projects behind me. I build interactive mascots, animated logos and icons, and UI animations, with View Models, reduced-motion paths and a clean developer handoff baked in.

See my work and get in touch: hireriveanimator.com

Have you shipped Rive semantics or reduced motion in production yet? Tell me in the comments what worked and what tripped you up.

Top comments (0)