Skip to content

Commit 994db53

Browse files
committed
feat(dialog): allow the removal of close icon on modal header
1 parent b559add commit 994db53

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

demo/DialogExamples.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export function DialogExamples() {
6565
Close from footer
6666
</button>
6767
)}
68+
staticBackdrop={true}
69+
useTimesClose={false}
6870
>
6971
<a href="">&amp;</a>
7072
</Dialog>

src/dialog/Dialog.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Dialog.propTypes = {
2929
size: PropTypes.oneOf(['sm', 'lg', 'xl', '']),
3030
staticBackdrop: PropTypes.bool,
3131
title: PropTypes.node,
32+
useTimesClose: PropTypes.bool,
3233
};
3334

3435
function DialogTrigger({ children, open }) {

src/dialog/Modal.jsx

+20-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ import { formatClasses } from '../utils/attributes';
66

77
const ESCAPE_KEYCODE = 27;
88

9-
export function Modal({ title, body, onClose, isOpen, footer, staticBackdrop, scrollable, centered, size, keyboard }) {
9+
export function Modal({
10+
body,
11+
centered,
12+
footer,
13+
isOpen,
14+
keyboard,
15+
onClose,
16+
scrollable,
17+
size,
18+
staticBackdrop,
19+
title,
20+
useTimesClose,
21+
}) {
1022
const modalRef = useRef(null);
1123
const closeAndHide = useCallback(() => {
1224
hideModal(modalRef);
@@ -65,9 +77,11 @@ export function Modal({ title, body, onClose, isOpen, footer, staticBackdrop, sc
6577
<div className="modal-content">
6678
<div className="modal-header">
6779
<h5 className="modal-title">{title}</h5>
68-
<button type="button" className="close" onClick={closeAndHide} aria-label="Close">
69-
<span aria-hidden="true">&times;</span>
70-
</button>
80+
{useTimesClose && (
81+
<button type="button" className="close" onClick={closeAndHide} aria-label="Close">
82+
<span aria-hidden="true">&times;</span>
83+
</button>
84+
)}
7185
</div>
7286
<div className="modal-body">{renderObjectOrFunction(body, { close: closeAndHide })}</div>
7387
{footer && <div className="modal-footer">{renderObjectOrFunction(footer, { close: closeAndHide })}</div>}
@@ -83,6 +97,7 @@ Modal.defaultProps = {
8397
scrollable: false,
8498
size: '',
8599
staticBackdrop: false,
100+
useTimesClose: true,
86101
};
87102

88103
Modal.propTypes = {
@@ -96,6 +111,7 @@ Modal.propTypes = {
96111
size: PropTypes.oneOf(['sm', 'lg', 'xl', '']),
97112
staticBackdrop: PropTypes.bool,
98113
title: PropTypes.node,
114+
useTimesClose: PropTypes.bool,
99115
};
100116

101117
function hideModal(modalRef) {

0 commit comments

Comments
 (0)