desktop: Respect reduced motion

Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Brandon Oxendine
2026-11-17 11:50:00 +01:00
committed by Rūdolfs Ošiņš
co-authored by Rūdolfs Ošiņš
parent efc6ae961f
commit 442e58780f
23 changed files with 119 additions and 53 deletions
+7
View File
@@ -155,6 +155,13 @@ Read `docs/adr/0005-boards.md` before working on boards.
### Svelte components
- Props use `$props()`: `const { foo, bar = undefined }: Props = $props()`
- Respect reduced motion. CSS transitions and animations are handled globally in
`public/index.css`. Anything driven from JS is not: wrap every Svelte
`transition:`/`in:`/`out:`/`animate:` duration, `element.animate()` duration,
and `setTimeout` that waits on an animation in `motion(ms)`, and use
`scrollBehavior()` instead of `behavior: "smooth"` (both from
`@app/lib/motion`). Custom transition functions apply `motion()` to the
durations they return.
### TypeScript
+13
View File
@@ -217,3 +217,16 @@ a {
-webkit-user-select: text;
user-select: text;
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0s !important;
animation-delay: 0s !important;
animation-iteration-count: 1 !important;
transition-duration: 0s !important;
transition-delay: 0s !important;
scroll-behavior: auto !important;
}
}
+17 -5
View File
@@ -11,6 +11,7 @@
import { hints } from "@app/lib/hints";
import { dynamicInterval } from "@app/lib/interval";
import { modalStore, show } from "@app/lib/modal";
import { motion } from "@app/lib/motion";
import {
badgeCount,
notificationCount,
@@ -114,7 +115,10 @@
function snapWidth() {
snapping = true;
if (snapTimeout !== undefined) clearTimeout(snapTimeout);
snapTimeout = setTimeout(() => (snapping = false), SNAP_DURATION_MS);
snapTimeout = setTimeout(
() => (snapping = false),
motion(SNAP_DURATION_MS),
);
}
// Held so unmounting mid-drag doesn't leave listeners and the body class
@@ -565,8 +569,12 @@
<div
class="view"
class:mini={isMini}
in:swap={{ duration: COLLAPSE_MS, rise: 8, width: bodyTargetWidth }}
out:swap={{ duration: COLLAPSE_MS }}>
in:swap={{
duration: motion(COLLAPSE_MS),
rise: 8,
width: bodyTargetWidth,
}}
out:swap={{ duration: motion(COLLAPSE_MS) }}>
<div
class="drag-strip"
style:height={dragStripHeight}
@@ -639,8 +647,12 @@
{#if !mini && notificationCount.value > 0}
<span
class="global-counter-badge"
in:scale={{ duration: 200, easing: backOut, start: 0 }}
out:fade={{ duration: 200 }}>
in:scale={{
duration: motion(200),
easing: backOut,
start: 0,
}}
out:fade={{ duration: motion(200) }}>
{notificationCount.value}
</span>
{/if}
+2 -1
View File
@@ -8,6 +8,7 @@
import { artifactNodeRunning } from "@app/lib/events";
import { invoke, InvokeError } from "@app/lib/invoke";
import { show } from "@app/lib/modal";
import { motion } from "@app/lib/motion";
import {
attestedBy,
canAttest,
@@ -796,7 +797,7 @@
</div>
{#if open}
<div class="details" transition:slide={{ duration: 180 }}>
<div class="details" transition:slide={{ duration: motion(180) }}>
<div class="section">
<div class="section-title">
Metadata
+2 -1
View File
@@ -17,6 +17,7 @@
import type { CommentOrigin } from "@app/lib/codeComments";
import { writeToClipboard } from "@app/lib/invoke";
import { scrollBehavior } from "@app/lib/motion";
import * as utils from "@app/lib/utils";
import DropdownList from "@app/components/DropdownList.svelte";
@@ -145,7 +146,7 @@
mode = "edit";
await tick();
utils.scrollIntoView(`edit-${id}`, {
behavior: "smooth",
behavior: scrollBehavior(),
block: "center",
});
} else if (mode === "edit") {
@@ -94,11 +94,6 @@
.avatars .avatar + .more {
margin-left: 0.25rem;
}
@media (prefers-reduced-motion: reduce) {
.avatars .avatar + .avatar {
transition: none;
}
}
.card {
display: flex;
flex-direction: column;
+3 -2
View File
@@ -8,6 +8,7 @@
import type { DraftReview } from "@app/lib/draftReviewStorage";
import { draftReviewStorage } from "@app/lib/draftReviewStorage";
import { motion } from "@app/lib/motion";
import { formatAnchor } from "@app/lib/pierreComments";
import { isPublishableReview, verdictBadge } from "@app/lib/utils";
@@ -573,8 +574,8 @@
<div
class="bar"
class:expanded
in:fly={{ y: 120, duration: 260, easing: backOut }}
out:fly={{ y: 120, duration: 180, easing: cubicIn }}>
in:fly={{ y: 120, duration: motion(260), easing: backOut }}
out:fly={{ y: 120, duration: motion(180), easing: cubicIn }}>
<textarea
bind:this={summaryEl}
class="summary"
+3 -1
View File
@@ -3,6 +3,8 @@
import { tick } from "svelte";
import { scrollBehavior } from "@app/lib/motion";
import Icon from "@app/components/Icon.svelte";
interface Props {
@@ -50,7 +52,7 @@
onToggle?.(expanded);
if (!expanded && header) {
await tick();
header.scrollIntoView({ behavior: "smooth", block: "nearest" });
header.scrollIntoView({ behavior: scrollBehavior(), block: "nearest" });
}
}
</script>
@@ -2,6 +2,7 @@
import { fade } from "svelte/transition";
import { hide, modalStore } from "@app/lib/modal";
import { motion } from "@app/lib/motion";
import { DRAG_REGION_HEIGHT } from "@app/lib/window";
// Only Tauri drags the window, and outside it the strip would do nothing but
@@ -48,7 +49,7 @@
role="button"
tabindex="0"
class="overlay"
transition:fade={{ duration: 120 }}
transition:fade={{ duration: motion(120) }}
onclick={$modalStore.disableScrimClose ? undefined : hide}
style:cursor={$modalStore.disableHide ? "not-allowed" : "default"}>
</div>
+3 -2
View File
@@ -22,6 +22,7 @@
referenceRoute,
toRadReference,
} from "@app/lib/mentions";
import { scrollBehavior } from "@app/lib/motion";
import type { Route } from "@app/lib/router";
import { push, routeToPath } from "@app/lib/router";
import { fetchingRepos } from "@app/lib/seedRepo";
@@ -226,12 +227,12 @@
/auto|scroll/.test(overflow) &&
node.scrollHeight > node.clientHeight
) {
node.scrollTo({ top: 0, behavior: "smooth" });
node.scrollTo({ top: 0, behavior: scrollBehavior() });
return;
}
node = node.parentElement;
}
window.scrollTo({ top: 0, behavior: "smooth" });
window.scrollTo({ top: 0, behavior: scrollBehavior() });
}
function isCurrentPage(candidate: Route): boolean {
@@ -14,6 +14,7 @@
import { itemDiff } from "@app/lib/cobActivity";
import { cachedConfig, writeToClipboard } from "@app/lib/invoke";
import { entityUrl } from "@app/lib/mentions";
import { motion } from "@app/lib/motion";
import { splitDescription } from "@app/lib/revisionDescription";
import {
absoluteTimestamp,
@@ -434,7 +435,7 @@
{/if}
</div>
{#if !firstRevision && desc.body && expanded && !bodyExternal}
<div class="revision-body" transition:slide={{ duration: 180 }}>
<div class="revision-body" transition:slide={{ duration: motion(180) }}>
<Markdown {rid} breaks content={desc.body} />
</div>
{/if}
+2 -1
View File
@@ -24,6 +24,7 @@
import { fontSettings } from "@app/lib/appearance.svelte";
import type { CodeComments } from "@app/lib/codeComments";
import { scrollBehavior } from "@app/lib/motion";
import { forwardPatchActivityContext } from "@app/lib/patchActivityContext";
import type {
CommentAnchor,
@@ -380,7 +381,7 @@
// is not the container's `scrollTop` and has to go through `scrollTo`.
function scrollToPosition(
position: number,
behavior: "smooth" | "instant" = "smooth",
behavior: "smooth" | "instant" = scrollBehavior(),
): void {
view?.scrollTo({ type: "position", position, behavior });
}
+7 -4
View File
@@ -34,6 +34,7 @@
cachedListCommits,
invoke,
} from "@app/lib/invoke";
import { motion } from "@app/lib/motion";
import type { PatchActivityData } from "@app/lib/patchTimeline";
import { patchTimeline } from "@app/lib/patchTimeline";
import { revisionRange } from "@app/lib/revisionCompare";
@@ -1173,7 +1174,9 @@
? ""
: (revBody ?? "")}
{#if expanded}
<div class="revision-card" transition:slide={{ duration: 180 }}>
<div
class="revision-card"
transition:slide={{ duration: motion(180) }}>
<PatchActivityItem
op={data.op}
{rid}
@@ -1286,7 +1289,7 @@
class="older-revisions txt-body-m-regular"
role="button"
tabindex="0"
transition:slide={{ duration: 180 }}
transition:slide={{ duration: motion(180) }}
onclick={() => expandCommitGroup(groupKey)}>
<div class="icon">
<span class="icon-stack">
@@ -1427,7 +1430,7 @@
{:else if isOlder}
<div
class="older-revision-entry"
transition:slide={{ duration: 180 }}>
transition:slide={{ duration: motion(180) }}>
<PatchActivityItem
op={data.op}
{rid}
@@ -1548,7 +1551,7 @@
class="older-revisions txt-body-m-regular"
role="button"
tabindex="0"
transition:slide={{ duration: 180 }}
transition:slide={{ duration: motion(180) }}
onclick={() => toggleRevisionRun(data.groupKey, data.revisionIds)}>
<div class="icon">
<span class="icon-stack">
+18 -14
View File
@@ -77,6 +77,7 @@
import { labs } from "@app/lib/labs";
import { entityUrl } from "@app/lib/mentions";
import { show } from "@app/lib/modal";
import { motion } from "@app/lib/motion";
import { repoListScope } from "@app/lib/repoListScope";
import * as router from "@app/lib/router";
import { seededRepos, seedRepo, setFetchingRepos } from "@app/lib/seedRepo";
@@ -310,7 +311,7 @@
// filter/refresh that should not animate at all.
fallback: (node: Element, params: CrossfadeParams & { key?: string }) =>
params.key !== undefined && params.key === unseedingRid
? fadeCollapse(node, ANIMATION_DURATION_MS)
? fadeCollapse(node, motion(ANIMATION_DURATION_MS))
: { duration: 0 },
});
@@ -364,7 +365,7 @@
if (animationTimeout !== undefined) clearTimeout(animationTimeout);
animationTimeout = setTimeout(() => {
animatingPinnedList = false;
}, ANIMATION_DURATION_MS);
}, motion(ANIMATION_DURATION_MS));
fn();
}
@@ -1021,9 +1022,9 @@
drag.dropPosition === "after" &&
drag.draggingRid !== repo.rid}
{...{ [DRAG_RID_ATTRIBUTE]: repo.rid }}
animate:flip={{ duration: animationDuration }}
in:receive={{ key: repo.rid, duration: animationDuration }}
out:send={{ key: repo.rid, duration: animationDuration }}
animate:flip={{ duration: motion(animationDuration) }}
in:receive={{ key: repo.rid, duration: motion(animationDuration) }}
out:send={{ key: repo.rid, duration: motion(animationDuration) }}
onoutroend={() => clearUnseeding(repo.rid)}>
{@render repoRowInner(repo, true)}
</div>
@@ -1092,8 +1093,8 @@
{#if !sidebarCollapsed.value && unpinnedReposCount > 1}
<span
class="global-counter-badge"
in:scale={{ duration: 200, easing: backOut, start: 0 }}
out:fade={{ duration: 200 }}>
in:scale={{ duration: motion(200), easing: backOut, start: 0 }}
out:fade={{ duration: motion(200) }}>
{unpinnedReposCount}
</span>
{/if}
@@ -1187,7 +1188,7 @@
{@const activeProject = activeRepo?.payloads["xyz.radicle.project"]}
<div
class="sub-items"
transition:slide={{ duration: ANIMATION_DURATION_MS }}>
transition:slide={{ duration: motion(ANIMATION_DURATION_MS) }}>
{#if labs.boards}
{@render subItem(
repo.name,
@@ -1259,8 +1260,8 @@
{#if !sidebarCollapsed.value && count !== undefined}
<span
class="global-counter-badge"
in:scale={{ duration: 200, easing: backOut, start: 0 }}
out:fade={{ duration: 200 }}>
in:scale={{ duration: motion(200), easing: backOut, start: 0 }}
out:fade={{ duration: motion(200) }}>
{count}
</span>
{/if}
@@ -1271,7 +1272,7 @@
{#if reposExpanded.value}
<div
class="repos-scroll"
transition:unroll|local={{ duration: ANIMATION_DURATION_MS }}>
transition:unroll|local={{ duration: motion(ANIMATION_DURATION_MS) }}>
<ScrollArea
style="mask-image: linear-gradient(to bottom, transparent 0, black 0.5rem, black calc(100% - 0.5rem), transparent 100%);">
<div class="repos-list scrolling">
@@ -1279,9 +1280,12 @@
<div
class="repo-row-group"
data-unpinned-rid={repo.rid}
animate:flip={{ duration: animationDuration }}
in:receive={{ key: repo.rid, duration: animationDuration }}
out:send={{ key: repo.rid, duration: animationDuration }}
animate:flip={{ duration: motion(animationDuration) }}
in:receive={{
key: repo.rid,
duration: motion(animationDuration),
}}
out:send={{ key: repo.rid, duration: motion(animationDuration) }}
onoutroend={() => clearUnseeding(repo.rid)}>
{@render repoRowInner(repo, false)}
</div>
+2 -1
View File
@@ -10,6 +10,7 @@
import type { Resolution } from "@app/lib/commentResolutions";
import { embedMap } from "@app/lib/embeds";
import { scrollBehavior } from "@app/lib/motion";
import { formatResolvedCaption, scrollIntoView } from "@app/lib/utils";
import CommentComponent from "@app/components/Comment.svelte";
@@ -98,7 +99,7 @@
await tick();
scrollIntoView(`reply-${root.id}`, {
behavior: "smooth",
behavior: scrollBehavior(),
block: "center",
});
}
+2 -1
View File
@@ -3,6 +3,7 @@ import type { Column } from "@bindings/cob/board/Column";
import { tick } from "svelte";
import type { BoardItem } from "@app/lib/board";
import { motion } from "@app/lib/motion";
const DRAG_THRESHOLD = 4;
const LANDING_MS = 160;
@@ -348,7 +349,7 @@ export class BoardDrag {
const slot = this.#slotPosition();
if (slot) {
this.#landing = slot;
await new Promise(resolve => setTimeout(resolve, LANDING_MS));
await new Promise(resolve => setTimeout(resolve, motion(LANDING_MS)));
}
const { item, over, index } = this.#drag;
+3 -1
View File
@@ -1,3 +1,5 @@
import { motion } from "@app/lib/motion";
// FLIP: animate elements from where they were to where a layout change just put
// them. Capture from `$effect.pre` and play from `$effect`, both reading the
// state that drives the change so they land on the same flush.
@@ -55,7 +57,7 @@ export function playFlip(
): void {
if (!container || !first) return;
const duration = options.durationMs ?? DEFAULT_DURATION_MS;
const duration = motion(options.durationMs ?? DEFAULT_DURATION_MS);
const base = container.getBoundingClientRect();
if (
+9
View File
@@ -0,0 +1,9 @@
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
export function motion(durationMs: number): number {
return reducedMotion.matches ? 0 : durationMs;
}
export function scrollBehavior(): "smooth" | "instant" {
return reducedMotion.matches ? "instant" : "smooth";
}
+2 -1
View File
@@ -12,6 +12,7 @@
validName,
} from "@app/lib/board";
import { disableHide, enableHide, hide } from "@app/lib/modal";
import { motion } from "@app/lib/motion";
import Button from "@app/components/Button.svelte";
import Icon from "@app/components/Icon.svelte";
@@ -295,7 +296,7 @@
class="row"
class:dragging={dragging === row.key}
data-row={row.key}
animate:flip={{ duration: 150, easing: cubicOut }}>
animate:flip={{ duration: motion(150), easing: cubicOut }}>
<button
class="icon-button handle"
title="Drag to reorder"
+3 -2
View File
@@ -2,6 +2,7 @@
import { cubicIn, cubicOut } from "svelte/easing";
import { fly } from "svelte/transition";
import { motion } from "@app/lib/motion";
import { comboKeys, shortcuts } from "@app/lib/shortcuts.svelte";
const rows = Object.values(shortcuts).map(s => ({
@@ -111,8 +112,8 @@
<div
class="modal"
in:fly={{ y: 8, duration: 160, easing: cubicOut }}
out:fly={{ y: 8, duration: 120, easing: cubicIn }}>
in:fly={{ y: 8, duration: motion(160), easing: cubicOut }}
out:fly={{ y: 8, duration: motion(120), easing: cubicIn }}>
<div class="header">
<span class="title">Keyboard shortcuts</span>
</div>
+8 -7
View File
@@ -59,6 +59,7 @@
import { nodeRunning } from "@app/lib/events";
import { invoke } from "@app/lib/invoke";
import { show } from "@app/lib/modal";
import { motion } from "@app/lib/motion";
import * as roles from "@app/lib/roles";
import * as router from "@app/lib/router";
import type { SidebarData } from "@app/lib/router/definitions";
@@ -319,11 +320,11 @@
// uses the separate scale property to leave that transform alone.
function filterOut(node: Element) {
if (node.classList.contains("placeholder")) {
return { duration: 150, css: (t: number) => `opacity: ${t};` };
return { duration: motion(150), css: (t: number) => `opacity: ${t};` };
}
if (!filtering) return { duration: 0 };
return {
duration: 180,
duration: motion(180),
easing: cubicOut,
css: (t: number) => `opacity: ${t}; scale: ${0.96 + 0.04 * t};`,
};
@@ -335,7 +336,7 @@
function arriveIn(node: HTMLElement) {
if (node.dataset.key !== arriving) return { duration: 0 };
arriving = undefined;
return slide(node, { duration: 220, easing: cubicOut });
return slide(node, { duration: motion(220), easing: cubicOut });
}
// An issue created from a column's add button or menu is placed at the end
@@ -1345,7 +1346,7 @@
class:lifted={dnd.liftedColumn === column.id}
class:refused={dnd.current?.refused === column.id}
data-column={column.id}
animate:flip={{ duration: 200, easing: cubicOut }}>
animate:flip={{ duration: motion(200), easing: cubicOut }}>
<div class="column-header">
{#if renaming?.id === column.id}
<!-- svelte-ignore a11y_autofocus -->
@@ -1393,7 +1394,7 @@
data-key={item.key}
role="button"
tabindex="0"
animate:flip={{ duration: 200, easing: cubicOut }}
animate:flip={{ duration: motion(200), easing: cubicOut }}
in:arriveIn
out:filterOut
onpointerdown={e => dnd.onCardPointerDown(e, item)}
@@ -1456,7 +1457,7 @@
data-key={item.key}
role="button"
tabindex="0"
animate:flip={{ duration: 200, easing: cubicOut }}
animate:flip={{ duration: motion(200), easing: cubicOut }}
in:arriveIn
out:filterOut
onpointerdown={e => dnd.onCardPointerDown(e, item)}
@@ -1494,7 +1495,7 @@
style:width="{drag.width}px">
{@render content(drag.item, view === "board" ? "card" : "row")}
{#if drag.refused && !landing}
<div class="refusal" transition:fade={{ duration: 150 }}>
<div class="refusal" transition:fade={{ duration: motion(150) }}>
<span class="refusal-icon"><Icon name="warning" /></span>
<span>{refusalFor(drag.item, drag.refused)}</span>
</div>
+4 -1
View File
@@ -5,6 +5,7 @@
import { slide } from "svelte/transition";
import { stateCaption, stateIcon } from "@app/lib/identityState";
import { motion } from "@app/lib/motion";
import type { SidebarData } from "@app/lib/router/definitions";
import {
absoluteTimestamp,
@@ -368,7 +369,9 @@
rev.rejected.length +
rev.pending.length}
{@const caption = stateCaption(rev.state)}
<div class="detail" transition:slide={{ duration: 180 }}>
<div
class="detail"
transition:slide={{ duration: motion(180) }}>
{#if caption}
<div class="state-caption">{caption}</div>
{/if}
+5 -1
View File
@@ -27,6 +27,7 @@
cachedListCommits,
invoke,
} from "@app/lib/invoke";
import { scrollBehavior } from "@app/lib/motion";
import { setPatchActivitySource } from "@app/lib/patchActivityContext";
import { patchContributions } from "@app/lib/patchContributions";
import type { ReviewEntry } from "@app/lib/reviewSummary";
@@ -163,7 +164,10 @@
const viewport = bottomSentinel?.closest<HTMLElement>(
"[data-overlayscrollbars-viewport]",
);
viewport?.scrollTo({ top: viewport.scrollHeight, behavior: "smooth" });
viewport?.scrollTo({
top: viewport.scrollHeight,
behavior: scrollBehavior(),
});
}
// A sentinel at the end of the scroll area, so "Jump to most recent" hides
// itself on a short patch or once you have scrolled down.