@@ -51,6 +51,7 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
5151 const aiAssistant = useShortcutsStore ( ( state ) => state . aiAssistant ) ;
5252 const [ assistants , setAssistants ] = useState < any [ ] > ( [ ] ) ;
5353 const [ isRefreshing , setIsRefreshing ] = useState ( false ) ;
54+ const popoverRef = useRef < HTMLDivElement > ( null ) ;
5455 const popoverButtonRef = useRef < HTMLButtonElement > ( null ) ;
5556 const searchInputRef = useRef < HTMLInputElement > ( null ) ;
5657 const [ keyword , setKeyword ] = useState ( "" ) ;
@@ -195,25 +196,41 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
195196 setTimeout ( ( ) => setIsRefreshing ( false ) , 1000 ) ;
196197 } ;
197198
198- useKeyPress ( [ "uparrow" , "downarrow" ] , ( _ , key ) => {
199- const isClose = isNil ( popoverButtonRef . current ?. dataset [ "open" ] ) ;
200- const index = assistants . findIndex (
201- ( item ) => item . _id === currentAssistant ?. _id
202- ) ;
203- const length = assistants . length ;
199+ useKeyPress (
200+ [ "uparrow" , "downarrow" , "enter" ] ,
201+ ( event , key ) => {
202+ const isClose = isNil ( popoverButtonRef . current ?. dataset [ "open" ] ) ;
204203
205- if ( isClose || length <= 1 ) return ;
204+ if ( isClose ) return ;
206205
207- let nextIndex = index ;
206+ event . stopPropagation ( ) ;
207+ event . preventDefault ( ) ;
208208
209- if ( key === "uparrow" ) {
210- nextIndex = index > 0 ? index - 1 : length - 1 ;
211- } else {
212- nextIndex = index < length - 1 ? index + 1 : 0 ;
213- }
209+ if ( key === "enter" ) {
210+ return popoverButtonRef . current ?. click ( ) ;
211+ }
214212
215- setCurrentAssistant ( assistants [ nextIndex ] ) ;
216- } ) ;
213+ const index = assistants . findIndex (
214+ ( item ) => item . _id === currentAssistant ?. _id
215+ ) ;
216+ const length = assistants . length ;
217+
218+ if ( length <= 1 ) return ;
219+
220+ let nextIndex = index ;
221+
222+ if ( key === "uparrow" ) {
223+ nextIndex = index > 0 ? index - 1 : length - 1 ;
224+ } else {
225+ nextIndex = index < length - 1 ? index + 1 : 0 ;
226+ }
227+
228+ setCurrentAssistant ( assistants [ nextIndex ] ) ;
229+ } ,
230+ {
231+ target : popoverRef ,
232+ }
233+ ) ;
217234
218235 const handlePrev = useCallback ( ( ) => {
219236 if ( pagination . current <= 1 ) return ;
@@ -231,7 +248,7 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
231248
232249 return (
233250 < div className = "relative" >
234- < Popover >
251+ < Popover ref = { popoverRef } >
235252 < PopoverButton
236253 ref = { popoverButtonRef }
237254 className = "h-6 p-1 px-1.5 flex items-center gap-1 rounded-full bg-white dark:bg-[#202126] text-sm/6 font-semibold text-gray-800 dark:text-[#d8d8d8] border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none"
@@ -326,6 +343,7 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
326343 ) }
327344 onClick = { ( ) => {
328345 setCurrentAssistant ( assistant ) ;
346+ popoverButtonRef . current ?. click ( ) ;
329347 } }
330348 >
331349 < div className = "flex items-center justify-center size-6 bg-white border border-[#E6E6E6] rounded-full overflow-hidden" >
0 commit comments