From adbab1bc8731ad3f72d06041126c61709cac8f6d Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Thu, 21 May 2026 07:22:55 +0200 Subject: [PATCH] feat(editor): directional slide transition between findings-tree levels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opening a finding category (e.g. "Dysfonction ostéopathique") and backing out felt abrupt — list content swapped instantly with no visual continuity. Now the list animates a short slide+fade between levels: - Drill down → new list enters from the right (+16px → 0). - Back / breadcrumb up → new list enters from the left (-16px → 0). Implementation: - Wrap the list in `motion.ul` keyed by the path string so React remounts when the level changes; motion's `initial`/`animate` variants then play on every remount. - A direction state (1 | -1) feeds the `enter` variant via `custom` so forward vs. back have opposite slide directions. - All path mutations go through `goInto` / `goBack` / `goToDepth` helpers that set direction before calling `setPath`. - 180ms ease-out — perceptible but does not block interaction. AnimatePresence was deliberately omitted: it defers DOM swap, which broke the existing synchronous `getByLabelText` assertions in components.FindingsTreePicker.test.tsx. The key-based remount keeps the new content reachable immediately while still providing a direction-aware entrance. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../observation/FindingsTreePicker.tsx | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/components/observation/FindingsTreePicker.tsx b/src/components/observation/FindingsTreePicker.tsx index b66c951f..afe483be 100644 --- a/src/components/observation/FindingsTreePicker.tsx +++ b/src/components/observation/FindingsTreePicker.tsx @@ -1,4 +1,5 @@ import { useMemo, useState } from 'react' +import { motion } from 'motion/react' import type { FindingNode, ZoneFindings, @@ -8,6 +9,11 @@ import Button from '@/components/ui/Button' import { useT } from '@/i18n/useT' import { useLocaleStore } from '@/state/localeStore' +const levelVariants = { + enter: (dir: 1 | -1) => ({ opacity: 0, x: dir * 16 }), + center: { opacity: 1, x: 0 }, +} + export interface FindingsTreePickerProps { zoneId: string tree: ZoneFindings @@ -63,6 +69,20 @@ export default function FindingsTreePicker({ locale === 'en' ? node.description_en : node.description_fr const [path, setPath] = useState([]) + const [direction, setDirection] = useState<1 | -1>(1) + + function goInto(nodePath: string[]) { + setDirection(1) + setPath(nodePath) + } + function goBack() { + setDirection(-1) + setPath(path.slice(0, -1)) + } + function goToDepth(depth: number) { + setDirection(depth >= path.length ? 1 : -1) + setPath(path.slice(0, depth)) + } const currentNodes = useMemo(() => { if (path.length === 0) return tree.categories @@ -136,7 +156,7 @@ export default function FindingsTreePicker({ )} -
    + {currentNodes.length === 0 ? (
  • {t('findings.no_options')} @@ -227,7 +255,7 @@ export default function FindingsTreePicker({
+ ) }