From 8f92bf33c3011b7618f8b1ab2cf6d0c34935b880 Mon Sep 17 00:00:00 2001 From: roormonger <34205054+roormonger@users.noreply.github.com> Date: Tue, 24 Mar 2026 14:38:18 -0400 Subject: [PATCH] even more navigation refinements --- src/components/GamesPage.tsx | 171 +++++++++++++++++++++++++++++------ src/hooks/useGamepad.ts | 15 +++ src/index.css | 10 +- 3 files changed, 166 insertions(+), 30 deletions(-) diff --git a/src/components/GamesPage.tsx b/src/components/GamesPage.tsx index d1a70d9..92b5582 100644 --- a/src/components/GamesPage.tsx +++ b/src/components/GamesPage.tsx @@ -11,29 +11,31 @@ interface FocusableItemProps { className?: string; focusKey?: string; scrollOptions?: ScrollIntoViewOptions; + active?: boolean; } -const FocusableItem = ({ onFocus, onEnterPress, children, className, focusKey, scrollOptions }: FocusableItemProps) => { +const FocusableItem = ({ onFocus, onEnterPress, children, className, focusKey, scrollOptions, active }: FocusableItemProps) => { const { mode } = useInputMode(); - const { ref, focused: rawFocused } = useFocusable({ - onFocus: () => { - onFocus(); - if (mode === 'gamepad') { - if (scrollOptions) { - ref.current?.scrollIntoView(scrollOptions); - } else { - ref.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); - } - } - }, + const { ref, focused: rawFocused, focusKey: internalFocusKey } = useFocusable({ + onFocus, onEnterPress, focusKey }); const focused = mode === 'gamepad' ? rawFocused : false; + useEffect(() => { + if (mode === 'gamepad' && (focused || active) && ref.current) { + if (scrollOptions) { + ref.current.scrollIntoView(scrollOptions); + } else { + ref.current.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); + } + } + }, [focused, active, mode, scrollOptions]); + return ( -