@@ -11,7 +11,7 @@ import {
11
11
useDisclosure ,
12
12
} from '@invoke-ai/ui-library' ;
13
13
import { useGalleryPagination } from 'features/gallery/hooks/useGalleryPagination' ;
14
- import { useCallback , useEffect , useState } from 'react' ;
14
+ import { useCallback , useEffect , useRef , useState } from 'react' ;
15
15
import { useHotkeys } from 'react-hotkeys-hook' ;
16
16
import { useTranslation } from 'react-i18next' ;
17
17
@@ -20,6 +20,16 @@ export const JumpTo = () => {
20
20
const { goToPage, currentPage, pages } = useGalleryPagination ( ) ;
21
21
const [ newPage , setNewPage ] = useState ( currentPage ) ;
22
22
const { isOpen, onToggle, onClose } = useDisclosure ( ) ;
23
+ const ref = useRef < HTMLInputElement > ( null ) ;
24
+
25
+ const onOpen = useCallback ( ( ) => {
26
+ setNewPage ( currentPage ) ;
27
+ setTimeout ( ( ) => {
28
+ const input = ref . current ?. querySelector ( 'input' ) ;
29
+ input ?. focus ( ) ;
30
+ input ?. select ( ) ;
31
+ } , 0 ) ;
32
+ } , [ currentPage ] ) ;
23
33
24
34
const onChangeJumpTo = useCallback ( ( v : number ) => {
25
35
setNewPage ( v - 1 ) ;
@@ -33,30 +43,40 @@ export const JumpTo = () => {
33
43
useHotkeys (
34
44
'enter' ,
35
45
( ) => {
36
- if ( isOpen ) {
37
- onClickGo ( ) ;
38
- }
46
+ onClickGo ( ) ;
39
47
} ,
48
+ { enabled : isOpen , enableOnFormTags : [ 'input' ] } ,
40
49
[ isOpen , onClickGo ]
41
50
) ;
42
51
52
+ useHotkeys (
53
+ 'esc' ,
54
+ ( ) => {
55
+ setNewPage ( currentPage ) ;
56
+ onClose ( ) ;
57
+ } ,
58
+ { enabled : isOpen , enableOnFormTags : [ 'input' ] } ,
59
+ [ isOpen , onClose ]
60
+ ) ;
61
+
43
62
useEffect ( ( ) => {
44
63
setNewPage ( currentPage ) ;
45
64
} , [ currentPage ] ) ;
46
65
47
66
return (
48
- < Popover isOpen = { isOpen } onClose = { onClose } >
67
+ < Popover isOpen = { isOpen } onClose = { onClose } onOpen = { onOpen } >
49
68
< PopoverTrigger >
50
- < Button aria-label = { t ( 'gallery.jump' ) } size = "xs " onClick = { onToggle } >
69
+ < Button aria-label = { t ( 'gallery.jump' ) } size = "sm " onClick = { onToggle } variant = "outline" >
51
70
{ t ( 'gallery.jump' ) }
52
71
</ Button >
53
72
</ PopoverTrigger >
54
73
< PopoverContent >
55
74
< PopoverArrow />
56
75
< PopoverBody >
57
- < Flex gap = { 2 } >
76
+ < Flex gap = { 2 } alignItems = "center" >
58
77
< FormControl >
59
78
< CompositeNumberInput
79
+ ref = { ref }
60
80
size = "sm"
61
81
maxW = "60px"
62
82
value = { newPage + 1 }
@@ -65,10 +85,10 @@ export const JumpTo = () => {
65
85
step = { 1 }
66
86
onChange = { onChangeJumpTo }
67
87
/>
68
- < Button size = "sm" onClick = { onClickGo } >
69
- { t ( 'gallery.go' ) }
70
- </ Button >
71
88
</ FormControl >
89
+ < Button h = "full" size = "sm" onClick = { onClickGo } >
90
+ { t ( 'gallery.go' ) }
91
+ </ Button >
72
92
</ Flex >
73
93
</ PopoverBody >
74
94
</ PopoverContent >
0 commit comments