diff --git a/src/components/ConfirmationModal/ConfirmationModal.test.tsx b/src/components/ConfirmationModal/ConfirmationModal.test.tsx
index a984f374d..73830c53b 100644
--- a/src/components/ConfirmationModal/ConfirmationModal.test.tsx
+++ b/src/components/ConfirmationModal/ConfirmationModal.test.tsx
@@ -55,4 +55,73 @@ describe("ConfirmationModal ", () => {
await userEvent.click(screen.getByText("Proceed"));
expect(onConfirm).toHaveBeenCalled();
});
+
+ it("should stop click event propagation on cancel by default", async () => {
+ const handleExternalClick = jest.fn();
+ render(
+
+
+ Test click propagation
+
+
+ );
+
+ await userEvent.click(screen.getByText("Go back"));
+ expect(handleExternalClick).not.toHaveBeenCalled();
+ });
+
+ it("should propagate click event on cancel", async () => {
+ const handleExternalClick = jest.fn();
+ render(
+
+
+ Test click propagation
+
+
+ );
+
+ await userEvent.click(screen.getByText("Go back"));
+ expect(handleExternalClick).toHaveBeenCalledTimes(1);
+ });
+
+ it("should stop click event propagation on confirm by default", async () => {
+ const handleExternalClick = jest.fn();
+ render(
+
+
+ Test click propagation
+
+
+ );
+
+ await userEvent.click(screen.getByText("Proceed"));
+ expect(handleExternalClick).not.toHaveBeenCalled();
+ });
+
+ it("should propagate click event on confirm", async () => {
+ const handleExternalClick = jest.fn();
+ render(
+
+
+ Test click propagation
+
+
+ );
+
+ await userEvent.click(screen.getByText("Proceed"));
+ expect(handleExternalClick).toHaveBeenCalledTimes(1);
+ });
});
diff --git a/src/components/ConfirmationModal/ConfirmationModal.tsx b/src/components/ConfirmationModal/ConfirmationModal.tsx
index b647790c1..41edfe55e 100644
--- a/src/components/ConfirmationModal/ConfirmationModal.tsx
+++ b/src/components/ConfirmationModal/ConfirmationModal.tsx
@@ -29,7 +29,7 @@ export type Props = PropsWithSpread<
/**
* Function to perform the action prompted by the modal.
*/
- onConfirm: (e: MouseEvent) => void;
+ onConfirm: (event: MouseEvent) => void;
},
Omit
>;
@@ -43,18 +43,32 @@ export const ConfirmationModal = ({
onConfirm,
...props
}: Props): ReactElement => {
+ const handleClick =
+ (action: A | null | undefined) =>
+ (event: MouseEvent) => {
+ if (!props.shouldPropagateClickEvent) {
+ event.stopPropagation();
+ }
+ if (action) {
+ action(event);
+ }
+ };
+
return (
{confirmExtra}
-