From 41ea2cdc5273e83145eb39433f2896e555461f27 Mon Sep 17 00:00:00 2001 From: RobbyV2 Date: Sat, 19 Jul 2025 12:40:01 -0700 Subject: [PATCH] Auto select navigation --- src/components/player/Navigator.tsx | 77 +++++++++++++++++++---------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/src/components/player/Navigator.tsx b/src/components/player/Navigator.tsx index 6e83a05..360498d 100644 --- a/src/components/player/Navigator.tsx +++ b/src/components/player/Navigator.tsx @@ -9,12 +9,25 @@ export const Navigator = ({ currentPage, numPages, skipToLocation }: { skipToLocation: (location: string | number, shouldPause?: boolean) => void; }) => { const [inputValue, setInputValue] = useState(''); + const [isPopoverOpen, setIsPopoverOpen] = useState(false); const inputRef = useRef(null); useEffect(() => { setInputValue(currentPage.toString()); }, [currentPage]); + // Auto-focus and select input when popover opens + useEffect(() => { + if (isPopoverOpen && inputRef.current) { + // Small delay to ensure the popover is fully rendered + const timer = setTimeout(() => { + inputRef.current?.focus(); + inputRef.current?.select(); + }, 50); + return () => clearTimeout(timer); + } + }, [isPopoverOpen]); + const handleInputChange = (e: React.ChangeEvent) => { // Only allow numbers const value = e.target.value.replace(/[^0-9]/g, ''); @@ -61,33 +74,43 @@ export const Navigator = ({ currentPage, numPages, skipToLocation }: { {/* Page number popup */} - -

- {currentPage} / {numPages || 1} -

-
- -
-
Go to page
- -
of {numPages || 1}
-
-
+ {({ open }) => { + if (open !== isPopoverOpen) { + setIsPopoverOpen(open); + } + + return ( + <> + +

+ {currentPage} / {numPages || 1} +

+
+ +
+
Go to page
+ +
of {numPages || 1}
+
+
+ + ); + }}
{/* Page forward */}