From 1ea560b825ddd2a3f0d9b6d74c0e6302216dc77e Mon Sep 17 00:00:00 2001 From: tisachi Date: Sat, 5 Sep 2026 03:31:54 +0200 Subject: [PATCH] Tabs: kierunkowy autoscroll do klikanej zakladki (lewa->lewa krawedz, prawa->prawa), snap wyciszony na czas animacji --- app/src/components/ui/content.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/components/ui/content.tsx b/app/src/components/ui/content.tsx index 6613818..c6da320 100644 --- a/app/src/components/ui/content.tsx +++ b/app/src/components/ui/content.tsx @@ -235,15 +235,25 @@ export function Tabs({ return () => window.removeEventListener('resize', onResize); }, [tabs.length]); - // aktywna zakładka zawsze w widoku + // automatyczny scroll kierunkowy: zakładka schowana bliżej lewej dosuwa się do + // lewej krawędzi, bliżej prawej — do prawej; snap wyciszony na czas animacji, + // żeby nie cofał wyrównania useEffect(() => { const el = scrollRef.current; const btn = el?.querySelector(`[data-tab-id="${CSS.escape(active)}"]`); if (!el || !btn) return; const br = btn.getBoundingClientRect(); const er = el.getBoundingClientRect(); - if (br.left < er.left) el.scrollBy({ left: br.left - er.left - 4, behavior: 'smooth' }); - else if (br.right > er.right) el.scrollBy({ left: br.right - er.right + 4, behavior: 'smooth' }); + let target: number | null = null; + if (br.left < er.left) target = el.scrollLeft + (br.left - er.left) - 4; + else if (br.right > er.right) target = el.scrollLeft + (br.right - er.right) + 4; + if (target == null) return; + el.style.scrollSnapType = 'none'; + el.scrollTo({ left: Math.max(0, target), behavior: 'smooth' }); + const t = window.setTimeout(() => { + el.style.scrollSnapType = ''; + }, 400); + return () => window.clearTimeout(t); }, [active]); const scrollByGroup = (dir: 1 | -1) => {