Skip to content

Commit 04092c7

Browse files
authored
Add Enter key support to trigger onConfirm in ConfirmationDialog (#624)
1 parent aa2446f commit 04092c7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/components/ConfirmationDialog/ConfirmationDialog.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,16 @@ describe("Dialog Component", () => {
130130
"You can't pass children and message props at the same time"
131131
);
132132
});
133+
134+
it("focuses the confirm button when dialog opens", async () => {
135+
const { getByTestId } = renderDialog({ open: true });
136+
const confirmButton = getByTestId("confirm-action-button");
137+
138+
expect(document.activeElement).toBe(confirmButton);
139+
});
140+
141+
it("does not focus when dialog is closed", () => {
142+
const { queryByTestId } = renderDialog({ open: false });
143+
expect(queryByTestId("confirm-action-button")).toBeNull();
144+
});
133145
});

src/components/ConfirmationDialog/ConfirmationDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const ConfirmationDialog = ({
8484
disabled={!!disabled || !!loading}
8585
type={primaryActionType}
8686
label={primaryActionLabel}
87+
autoFocus={open}
8788
onClick={() => {
8889
if (onConfirm) {
8990
onConfirm();

0 commit comments

Comments
 (0)