Skip to content

Commit a431ead

Browse files
authored
feat: support Tab and Enter for delete dialog buttons (#700)
* feat: support `Tab` and `Enter` for delete dialog buttons * docs: update changelog * refactor: update
1 parent 7ec41df commit a431ead

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Information about release notes of Coco Server is provided here.
1313

1414
### 🚀 Features
1515

16+
- feat: support `Tab` and `Enter` for delete dialog buttons #700
17+
1618
### 🐛 Bug fix
1719

1820
- fix: quick ai state synchronous #693

src/components/Common/HistoryList/DeleteDialog.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Button,
23
Description,
34
Dialog,
45
DialogPanel,
@@ -8,6 +9,7 @@ import { useTranslation } from "react-i18next";
89

910
import VisibleKey from "@/components/Common/VisibleKey";
1011
import { Chat } from "@/types/chat";
12+
import { KeyboardEvent } from "react";
1113

1214
interface DeleteDialogProps {
1315
isOpen: boolean;
@@ -24,6 +26,15 @@ const DeleteDialog = ({
2426
}: DeleteDialogProps) => {
2527
const { t } = useTranslation();
2628

29+
const handleEnter = (event: KeyboardEvent, cb: () => void) => {
30+
if (event.code !== "Enter") return;
31+
32+
event.stopPropagation();
33+
event.preventDefault();
34+
35+
cb();
36+
};
37+
2738
return (
2839
<Dialog
2940
open={isOpen}
@@ -56,25 +67,34 @@ const DeleteDialog = ({
5667
shortcutClassName="left-[unset] right-0"
5768
onKeyPress={() => setIsOpen(false)}
5869
>
59-
<button
60-
className="h-8 px-4 text-sm text-[#666666] bg-[#F8F9FA] dark:text-white dark:bg-[#202126] border border-[#E6E6E6] dark:border-white/10 rounded-lg"
70+
<Button
71+
autoFocus
72+
className="h-8 px-4 text-sm text-[#666666] bg-[#F8F9FA] dark:text-white dark:bg-[#202126] border border-[#E6E6E6] dark:border-white/10 rounded-lg focus:border-black/30 dark:focus:border-white/50 transition"
6173
onClick={() => setIsOpen(false)}
74+
onKeyDown={(event) => {
75+
handleEnter(event, () => {
76+
setIsOpen(false);
77+
});
78+
}}
6279
>
6380
{t("history_list.delete_modal.button.cancel")}
64-
</button>
81+
</Button>
6582
</VisibleKey>
6683

6784
<VisibleKey
6885
shortcut="Y"
6986
shortcutClassName="left-[unset] right-0"
7087
onKeyPress={handleRemove}
7188
>
72-
<button
73-
className="h-8 px-4 text-sm text-white bg-[#EF4444] rounded-lg"
89+
<Button
90+
className="h-8 px-4 text-sm text-white bg-[#EF4444] rounded-lg border border-[#EF4444] focus:border-black/30 dark:focus:border-white/50 transition"
7491
onClick={handleRemove}
92+
onKeyDown={(event) => {
93+
handleEnter(event, handleRemove);
94+
}}
7595
>
7696
{t("history_list.delete_modal.button.delete")}
77-
</button>
97+
</Button>
7898
</VisibleKey>
7999
</div>
80100
</DialogPanel>

0 commit comments

Comments
 (0)