Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(a11y): make JS smooth-scrolls honor prefers-reduced-motion

Juan Denis58dce6225b12
diff --git a/frontend/src/components/JobProgressModal.jsx b/frontend/src/components/JobProgressModal.jsx
index cb09e98f..cf3d2196 100644
--- a/frontend/src/components/JobProgressModal.jsx
+++ b/frontend/src/components/JobProgressModal.jsx
@@ -3,6 +3,7 @@ import Modal from './Modal';
import { Button } from '@/components/ui/button';
import { rooms, SOCKET_EVENTS } from '@/constants/events';
import { useServerStream } from '@/hooks/useServerStream';
+import { scrollBehavior } from '@/utils/reducedMotion';
import { useTranslation } from 'react-i18next';
// Subscribes to a remote agent's job:<id> stream channel and renders
@@ -63,7 +64,7 @@ export default function JobProgressModal({
// Auto-scroll to the bottom as new lines arrive.
useEffect(() => {
- logEndRef.current?.scrollIntoView({ behavior: 'smooth' });
+ logEndRef.current?.scrollIntoView({ behavior: scrollBehavior() });
}, [lines.length]);
const success = done && done.exitCode === 0 && !done.error;
diff --git a/frontend/src/components/deploy-console/LogPane.jsx b/frontend/src/components/deploy-console/LogPane.jsx
index c942bfef..e5a5e01e 100644
--- a/frontend/src/components/deploy-console/LogPane.jsx
+++ b/frontend/src/components/deploy-console/LogPane.jsx
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ArrowDown, ChevronDown, ChevronRight } from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import { scrollBehavior } from '@/utils/reducedMotion';
// How many slices the severity map is divided into. Enough to resolve a single
// error in a long log without rendering a node per line.
@@ -97,7 +98,7 @@ export default function LogPane({
useEffect(() => {
if (scrollToStep == null || !paneRef.current) return;
const el = paneRef.current.querySelector(`[data-step="${scrollToStep}"]`);
- if (el) el.scrollIntoView({ block: 'start', behavior: 'smooth' });
+ if (el) el.scrollIntoView({ block: 'start', behavior: scrollBehavior() });
}, [scrollToStep]);
// Jump to a specific line — prev/next navigation, and the first error when
@@ -107,7 +108,7 @@ export default function LogPane({
if (!scrollTarget || !paneRef.current) return;
const el = paneRef.current.querySelector(`[data-line="${scrollTarget.index}"]`);
if (!el) return;
- el.scrollIntoView({ block: 'center', behavior: 'smooth' });
+ el.scrollIntoView({ block: 'center', behavior: scrollBehavior() });
setActiveLine(scrollTarget.index);
}, [scrollTarget]);
diff --git a/frontend/src/hooks/useSettingFocus.js b/frontend/src/hooks/useSettingFocus.js
index 124a425b..443f816f 100644
--- a/frontend/src/hooks/useSettingFocus.js
+++ b/frontend/src/hooks/useSettingFocus.js
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState, useCallback } from 'react';
import useFocusParam from './useFocusParam';
+import { scrollBehavior } from '@/utils/reducedMotion';
/**
* Settings deep-link focus (plan 41, Phase 2). A settings tab calls this hook
@@ -37,7 +38,7 @@ export default function useSettingFocus() {
const tryScroll = () => {
const el = refs.current.get(focusedId);
if (el) {
- el.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ el.scrollIntoView({ behavior: scrollBehavior(), block: 'center' });
clearTimer = setTimeout(() => setFocusedId(null), 2000);
return;
}
diff --git a/frontend/src/pages/Backups.jsx b/frontend/src/pages/Backups.jsx
index bf60c0dc..e729b61f 100644
--- a/frontend/src/pages/Backups.jsx
+++ b/frontend/src/pages/Backups.jsx
@@ -3,6 +3,7 @@ import useTabParam from '../hooks/useTabParam';
import { Upload, Check, AlertTriangle, Archive, Clock, Database, Package, FolderArchive, HardDrive, History, Cloud, RefreshCw, Trash2, Plus, FileArchive, DollarSign } from 'lucide-react';
import api from '../services/api';
import { formatBytes } from '@/utils/formatBytes';
+import { scrollBehavior } from '@/utils/reducedMotion';
import { useToast } from '../contexts/ToastContext';
import { useConfirm } from '../hooks/useConfirm';
import EmptyState from '../components/EmptyState';
@@ -861,7 +862,7 @@ const Backups = () => {
onTest={handleTestConnection}
onBrowse={() => setActiveTab('snapshots')}
onAdd={() => {
- document.getElementById('bk-storage-form')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
+ document.getElementById('bk-storage-form')?.scrollIntoView({ behavior: scrollBehavior(), block: 'start' });
}}
/>
diff --git a/frontend/src/pages/Downloads.jsx b/frontend/src/pages/Downloads.jsx
index d54f8606..cde7b100 100644
--- a/frontend/src/pages/Downloads.jsx
+++ b/frontend/src/pages/Downloads.jsx
@@ -3,6 +3,7 @@ import api from '../services/api';
import { Button } from '@/components/ui/button';
import { useTopbarActions } from '@/hooks/useTopbarActions';
import { copyToClipboard } from '@/utils/clipboard';
+import { scrollBehavior } from '@/utils/reducedMotion';
import { useTranslation } from 'react-i18next';
// Platform icons as SVG components
@@ -190,7 +191,7 @@ function Downloads() {
)}
<a href="#downloads" className="btn btn-banner-primary" onClick={(e) => {
e.preventDefault();
- document.querySelector('.download-cards')?.scrollIntoView({ behavior: 'smooth' });
+ document.querySelector('.download-cards')?.scrollIntoView({ behavior: scrollBehavior() });
}}>
<DownloadIcon />
{t('app.downloads.downloadNow', 'Download Now')}
diff --git a/frontend/src/utils/reducedMotion.js b/frontend/src/utils/reducedMotion.js
new file mode 100644
index 00000000..e1036868
--- /dev/null
+++ b/frontend/src/utils/reducedMotion.js
@@ -0,0 +1,15 @@
+/**
+ * prefers-reduced-motion for imperative (JS) callers.
+ *
+ * CSS transitions/animations are already neutralized globally in
+ * styles/base/_reset.scss, but JS-driven scrolling bypasses stylesheets —
+ * so scroll calls ask here instead of hardcoding `behavior: 'smooth'`.
+ */
+export function prefersReducedMotion() {
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false;
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
+}
+
+export function scrollBehavior() {
+ return prefersReducedMotion() ? 'auto' : 'smooth';
+}