Skip to content

Commit 5a25b34

Browse files
committed
fix(dialog): prevent click propagation on ConfirmationDialog
1 parent 6318959 commit 5a25b34

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/dialog/ConfirmationDialog.jsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { Dialog } from './Dialog';
4-
import { awaitForAsyncTask } from '../utils/event-handlers';
4+
import { awaitForAsyncTask, safeClick } from '../utils/event-handlers';
55

6-
export function ConfirmationDialog({ title, message, children, onProceed, onCancel, cancelLabel, proceedLabel }) {
6+
export function ConfirmationDialog({
7+
title,
8+
message,
9+
children,
10+
onProceed,
11+
onCancel,
12+
cancelLabel,
13+
proceedLabel,
14+
proceedType,
15+
}) {
716
return (
817
<Dialog
918
title={title}
1019
body={message}
1120
footer={({ close }) => (
1221
<>
13-
<button type="button" className="btn btn-secondary" onClick={awaitForAsyncTask(onCancel, close)}>
22+
<button type="button" className="btn btn-secondary" onClick={safeClick(awaitForAsyncTask(onCancel, close))}>
1423
{cancelLabel}
1524
</button>
16-
<button type="button" className="btn btn-primary" onClick={awaitForAsyncTask(onProceed, close)}>
25+
<button
26+
type="button"
27+
className={`btn btn-${proceedType}`}
28+
onClick={safeClick(awaitForAsyncTask(onProceed, close))}
29+
>
1730
{proceedLabel}
1831
</button>
1932
</>
@@ -30,6 +43,7 @@ ConfirmationDialog.defaultProps = {
3043
title: 'Atention required',
3144
cancelLabel: 'Cancel',
3245
proceedLabel: 'Proceed',
46+
proceedType: 'primary',
3347
};
3448

3549
ConfirmationDialog.propTypes = {
@@ -40,4 +54,5 @@ ConfirmationDialog.propTypes = {
4054
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
4155
cancelLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
4256
proceedLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
57+
proceedType: PropTypes.oneOf(['primary', 'danger', 'success']),
4358
};

0 commit comments

Comments
 (0)