Reduced motion should not erase the result of an interaction
A disclosure control often has two separate responsibilities that are easy to accidentally merge. It must change state when activated, and it may animate that change to make the interaction feel responsive. A reduced-motion preference should affect the second responsibility, not the first.
The implementation uses one expanded-state value as the source of truth. That state determines whether the panel is hidden, whether the control exposes an expanded value, and which persistent cues are shown. When open, the button uses a “Hide details” label, an expanded icon, and an active color. When closed, those cues return to their collapsed equivalents.
The motion policy is independent. Under the normal preference, the panel can transition its size and opacity. Under prefers-reduced-motion: reduce, the matching CSS rule removes the transition. The panel still opens and closes; it simply reaches its state without interaction-triggered animation.
This distinction matters because an instant layout change is not always a sufficient explanation. If a control keeps the same label and appearance after activation, users may need to infer the result from nearby content. Persistent text, icon, color, semantic state, and expanded content make the result readable even when someone sees only the final frame.
The example’s tests focus on that contract: reduced motion changes the transition policy while expanded and collapsed states still expose the correct labels, visibility, and attributes. They do not prove operating-system or browser media-query behavior, nor do they establish accessibility compliance on their own.
Use this approach for disclosures, accordions, menus, and similar controls where motion is supportive. It is not enough when motion itself carries essential information; in that case, expose the sequence or result through text, structure, or another non-motion representation.
Working example
// This controller models the state that a disclosure button exposes to its UI. // The CSS below is meant to be applied in a browser; Node tests only prove the // controller's state and motion-policy behavior, not browser media-query matching. export const disclosureCss = ` .disclosure-panel { max-height: 0; opacity: 0; overflow: clip; transition: max-height 180ms ease, opacity 180ms ease; } .disclosure-panel[data-expanded="true"] { max-height: 20rem; opacity: 1; } .disclosure-button[data-expanded="true"] { color: #075985; } @media (prefers-reduced-motion: reduce) { .disclosure-panel { transition: none; } } `; const labels = { collapsed: { text: 'Show details', icon: '›' }, expanded: { text: 'Hide details', icon: '⌄' }, }; function validateMotionPreference(motionPreference) { if (motionPreference !== 'no-preference' && motionPreference !== 'reduce') { throw new RangeError( 'motionPreference must be "no-preference" or "reduce"', ); } } /** * Creates an interaction controller for a disclosure control. * `motionPreference` represents the result of the browser/OS preference check. */ export function createDisclosure({ motionPreference = 'no-preference' } = {}) { validateMotionPreference(motionPreference); let expanded = false; function view() { const label = labels[expanded ? 'expanded' : 'collapsed']; const motionReduced = motionPreference === 'reduce'; return { button: { ariaExpanded: String(expanded), dataExpanded: String(expanded), text: label.text, icon: label.icon, color: expanded ? '#075985' : '#1f2937', }, panel: { hidden: !expanded, dataExpanded: String(expanded), transition: motionReduced ? 'none' : 'max-height 180ms ease, opacity 180ms ease', }, }; } return { dispatch(command) { if (command !== 'toggle') { throw new RangeError('Unsupported command: ' + command); } expanded = !expanded; return view(); }, view, }; } Read the full article: https://chriseugenerodriguez.com/blog/preserve-control-state-when-motion-is-reduced

