Skip to content

Commit 5bffb7f

Browse files
authored
Merge pull request #863 from 2379278408/fix/862-internal-command-dialog-keyboard
fix(frontend): support arrow navigation in slash command dialog
2 parents 673eb70 + 5818641 commit 5bffb7f

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

frontend/src/components/console/task/chat-inputbox.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export const TaskChatInputBox = React.forwardRef<TaskChatInputBoxHandle, TaskCha
128128
const fileInputRef = useRef<HTMLInputElement>(null)
129129
const quickInputContainerRef = useRef<HTMLDivElement>(null)
130130
const quickInputMeasureRef = useRef<HTMLDivElement>(null)
131+
const slashCommandCancelRef = useRef<HTMLButtonElement>(null)
132+
const slashCommandConfirmRef = useRef<HTMLButtonElement>(null)
131133
const dragDepthRef = useRef(0)
132134
const nextAttachmentFileIndexRef = useRef(1)
133135
const autoSendingQueuedInputRef = useRef(false)
@@ -437,6 +439,19 @@ export const TaskChatInputBox = React.forwardRef<TaskChatInputBoxHandle, TaskCha
437439
void sendCurrentInput()
438440
}
439441

442+
const handleSlashCommandDialogKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
443+
if (event.key === "ArrowLeft") {
444+
event.preventDefault()
445+
slashCommandCancelRef.current?.focus()
446+
return
447+
}
448+
449+
if (event.key === "ArrowRight") {
450+
event.preventDefault()
451+
slashCommandConfirmRef.current?.focus()
452+
}
453+
}
454+
440455
const handleTextRecognized = (text: string) => {
441456
selectedQuickInputRef.current = null
442457
setContent(text)
@@ -1121,16 +1136,16 @@ export const TaskChatInputBox = React.forwardRef<TaskChatInputBoxHandle, TaskCha
11211136
}}
11221137
/>
11231138
<AlertDialog open={slashCommandConfirmOpen} onOpenChange={setSlashCommandConfirmOpen}>
1124-
<AlertDialogContent>
1139+
<AlertDialogContent onKeyDown={handleSlashCommandDialogKeyDown}>
11251140
<AlertDialogHeader>
11261141
<AlertDialogTitle>{t("taskDetail.chat.slashCommand.title")}</AlertDialogTitle>
11271142
<AlertDialogDescription>
11281143
{t("taskDetail.chat.slashCommand.description")}
11291144
</AlertDialogDescription>
11301145
</AlertDialogHeader>
11311146
<AlertDialogFooter>
1132-
<AlertDialogCancel>{t("taskDetail.common.cancel")}</AlertDialogCancel>
1133-
<AlertDialogAction onClick={handleConfirmSlashCommand}>
1147+
<AlertDialogCancel ref={slashCommandCancelRef}>{t("taskDetail.common.cancel")}</AlertDialogCancel>
1148+
<AlertDialogAction ref={slashCommandConfirmRef} onClick={handleConfirmSlashCommand}>
11341149
{t("taskDetail.chat.slashCommand.confirm")}
11351150
</AlertDialogAction>
11361151
</AlertDialogFooter>

0 commit comments

Comments
 (0)