diff --git a/src/app/globals.css b/src/app/globals.css index cc6e191..c105294 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -75,8 +75,10 @@ body::before { border-radius: 3px; } +/* Scroll margin to keep focused items visible during keyboard navigation */ [data-nav-id] { - scroll-margin: 200px; + scroll-margin-block: 100px 150px; + /* top: 100px, bottom: 150px for shortcuts bar */ } html { @@ -750,4 +752,4 @@ body.theme-flash::after { backface-visibility: hidden; -webkit-perspective: 1000px; perspective: 1000px; -} +} \ No newline at end of file diff --git a/src/hooks/useKeyboardNavigation.ts b/src/hooks/useKeyboardNavigation.ts index 17c6823..6832e6a 100644 --- a/src/hooks/useKeyboardNavigation.ts +++ b/src/hooks/useKeyboardNavigation.ts @@ -138,7 +138,7 @@ export function useKeyboardNavigation( return () => window.removeEventListener('keydown', handleKeyDown); }, [navItems, focusPos, onToggleCategory, onToggleApp]); - /* Scroll focused item into view automatically */ + /* Scroll focused item into view instantly */ useEffect(() => { if (!focusPos) return; @@ -150,13 +150,14 @@ export function useKeyboardNavigation( ); if (!el) return; - + el.scrollIntoView({ - block: 'nearest', + behavior: 'auto', + block: 'center', inline: 'nearest', }); }, [focusPos, navItems]); - + return { focusPos, focusedItem,