Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-9531]): honor reduced motion in tab scrolling (#9554)

[._.]/295972cb0b00
diff --git a/client/src/components/ui/TabPills.jsx b/client/src/components/ui/TabPills.jsx
index 416f1edc1d..02e87d2691 100644
--- a/client/src/components/ui/TabPills.jsx
+++ b/client/src/components/ui/TabPills.jsx
@@ -38,6 +38,7 @@
// count (e.g. PipelineIssue's per-stage status dot).
import { useRef, useEffect, useState, useCallback } from 'react';
import { ChevronLeft, ChevronRight, Loader2 } from 'lucide-react';
+import usePrefersReducedMotion from '../../hooks/usePrefersReducedMotion';
const SIZE = {
xs: { text: 'text-[11px]', icon: 11, padding: 'px-2 py-2', gap: 'gap-1' },
@@ -66,6 +67,8 @@ export default function TabPills({
className = '',
}) {
const sz = SIZE[size] || SIZE.md;
+ const reducedMotion = usePrefersReducedMotion();
+ const scrollBehavior = reducedMotion ? 'instant' : 'smooth';
const visibleTabs = tabs.filter(Boolean);
const tabRefs = useRef([]);
const stripRef = useRef(null);
@@ -99,8 +102,8 @@ export default function TabPills({
const delta = tabBounds.left < left
? tabBounds.left - left
: Math.max(0, tabBounds.right - right);
- if (delta) strip.scrollBy({ left: delta, behavior: 'smooth' });
- }, [activeTab, activeIndex, variant]);
+ if (delta) strip.scrollBy({ left: delta, behavior: scrollBehavior });
+ }, [activeTab, activeIndex, variant, scrollBehavior]);
// Scroll path: position only, against the cached extent.
const syncPosition = useCallback(() => {
@@ -131,7 +134,7 @@ export default function TabPills({
const scrollStrip = (direction) => {
const strip = stripRef.current;
- if (strip) strip.scrollBy({ left: direction * strip.clientWidth * 0.8, behavior: 'smooth' });
+ if (strip) strip.scrollBy({ left: direction * strip.clientWidth * 0.8, behavior: scrollBehavior });
};
const handleTabKeyDown = (event, index) => {
diff --git a/client/src/components/ui/TabPills.test.jsx b/client/src/components/ui/TabPills.test.jsx
index 473c653f20..1835edfeda 100644
--- a/client/src/components/ui/TabPills.test.jsx
+++ b/client/src/components/ui/TabPills.test.jsx
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi } from 'vitest';
+import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, screen, within, fireEvent, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Users, MapPin, Package } from 'lucide-react';
@@ -11,6 +11,18 @@ const sampleTabs = [
{ id: 'objects', label: 'Objects', icon: Package },
];
+afterEach(() => vi.restoreAllMocks());
+
+function setMotionPreference(initial) {
+ const media = new EventTarget();
+ media.matches = initial;
+ vi.spyOn(window, 'matchMedia').mockReturnValue(media);
+ return (reduced) => act(() => {
+ media.matches = reduced;
+ media.dispatchEvent(new Event('change'));
+ });
+}
+
describe('TabPills — underline variant (default)', () => {
it('renders one button per tab with role="tab" and aria-selected on the active one', () => {
render(<TabPills tabs={sampleTabs} activeTab="places" onChange={() => {}} />);
@@ -171,7 +183,9 @@ describe('TabPills — mobileCompact icon row', () => {
expect(castBtn.querySelector('svg')).toBeTruthy();
});
- it.each(['underline', 'pills'])('reveals a scrollable edge with a chevron in the %s variant', async (variant) => {
+ it.each([['underline', false], ['pills', true]])('scrolls either chevron in the %s variant with reduced motion=%s and live changes', async (variant, reduced) => {
+ const changePreference = setMotionPreference(reduced);
+ const behavior = reduced ? 'instant' : 'smooth';
// happy-dom reports every box as 0x0 and ships no ResizeObserver, so both
// the overflow and the re-measure that publishes it have to be stated. The
// fake observer is also what proves the split: the scroll path alone never
@@ -196,12 +210,17 @@ describe('TabPills — mobileCompact icon row', () => {
expect(screen.queryByRole('button', { name: 'Scroll tabs left' })).toBeNull();
await user.click(screen.getByRole('button', { name: 'Scroll tabs right' }));
- expect(scrollBy).toHaveBeenCalledWith({ left: 240, behavior: 'smooth' });
+ expect(scrollBy).toHaveBeenCalledWith({ left: 240, behavior });
strip.scrollLeft = 200;
fireEvent.scroll(strip);
await user.click(screen.getByRole('button', { name: 'Scroll tabs left' }));
- expect(scrollBy).toHaveBeenLastCalledWith({ left: -240, behavior: 'smooth' });
+ expect(scrollBy).toHaveBeenLastCalledWith({ left: -240, behavior });
+ changePreference(!reduced);
+ await user.click(screen.getByRole('button', { name: 'Scroll tabs right' }));
+ expect(scrollBy).toHaveBeenLastCalledWith({ left: 240, behavior: reduced ? 'smooth' : 'instant' });
+ await user.click(screen.getByRole('button', { name: 'Scroll tabs left' }));
+ expect(scrollBy).toHaveBeenLastCalledWith({ left: -240, behavior: reduced ? 'smooth' : 'instant' });
vi.unstubAllGlobals();
});
@@ -303,7 +322,9 @@ describe('TabPills — filter variant', () => {
});
});
-it('reveals tabs horizontally without moving ancestors or stealing draft focus', () => {
+it.each([false, true])('reveals tabs with reduced motion=%s without moving ancestors or stealing draft focus', (reduced) => {
+ const changePreference = setMotionPreference(reduced);
+ const behavior = reduced ? 'instant' : 'smooth';
const ancestorScroll = vi.spyOn(HTMLElement.prototype, 'scrollIntoView');
const view = (activeTab, tabs) => <><TabPills tabs={tabs} activeTab={activeTab} onChange={vi.fn()} /><input aria-label="Draft" /></>;
const { rerender } = render(view('cast', []));
@@ -317,7 +338,8 @@ it('reveals tabs horizontally without moving ancestors or stealing draft focus',
const draft = screen.getByRole('textbox', { name: 'Draft' });
draft.focus();
rerender(view('places', sampleTabs));
- expect(scroll).toHaveBeenLastCalledWith({ left: 60, behavior: 'smooth' });
+ expect(scroll).toHaveBeenLastCalledWith({ left: 60, behavior });
+ expect(places).toHaveAttribute('aria-selected', 'true');
rerender(view('places', sampleTabs.map(tab => ({ ...tab, count: 10 }))));
expect(scroll).toHaveBeenCalledTimes(1);
expect(draft).toHaveFocus();
@@ -326,6 +348,11 @@ it('reveals tabs horizontally without moving ancestors or stealing draft focus',
const cast = screen.getByRole('tab', { name: /Cast/ });
vi.spyOn(cast, 'getBoundingClientRect').mockReturnValue({ left: -80, right: 20 });
rerender(view('cast', sampleTabs));
- expect(scroll).toHaveBeenLastCalledWith({ left: -80, behavior: 'smooth' });
+ expect(scroll).toHaveBeenLastCalledWith({ left: -80, behavior });
+ changePreference(!reduced);
+ expect(scroll).toHaveBeenLastCalledWith({ left: -80, behavior: reduced ? 'smooth' : 'instant' });
+ expect(cast).toHaveAttribute('aria-selected', 'true');
+ expect(draft).toHaveFocus();
+ expect(ancestorScroll).not.toHaveBeenCalled();
ancestorScroll.mockRestore();
});