diff --git a/src/components/config/VisualConfigEditor.tsx b/src/components/config/VisualConfigEditor.tsx index 46a0a61..d4751a6 100644 --- a/src/components/config/VisualConfigEditor.tsx +++ b/src/components/config/VisualConfigEditor.tsx @@ -196,6 +196,7 @@ export function VisualConfigEditor({ const sidebarAnchorRef = useRef(null); const floatingSidebarRef = useRef(null); const sectionRefs = useRef>>({}); + const mobileNavScrollerRef = useRef(null); const mobileNavButtonRefs = useRef>>( {} ); @@ -360,9 +361,22 @@ export function VisualConfigEditor({ useEffect(() => { if (!isMobile) return; - mobileNavButtonRefs.current[activeSectionId]?.scrollIntoView({ - block: 'nearest', - inline: 'center', + const scroller = mobileNavScrollerRef.current; + const button = mobileNavButtonRefs.current[activeSectionId]; + if (!scroller || !button) return; + + const scrollerRect = scroller.getBoundingClientRect(); + const buttonRect = button.getBoundingClientRect(); + const centeredLeft = + scroller.scrollLeft + + (buttonRect.left - scrollerRect.left) - + (scroller.clientWidth - buttonRect.width) / 2; + const maxScrollLeft = Math.max(scroller.scrollWidth - scroller.clientWidth, 0); + const targetLeft = Math.min(Math.max(centeredLeft, 0), maxScrollLeft); + + scroller.scrollTo({ + left: targetLeft, + behavior: 'smooth', }); }, [activeSectionId, isMobile]); @@ -546,6 +560,7 @@ export function VisualConfigEditor({ {isMobile ? (