Skip to content

Commit dca61bd

Browse files
authored
create contentClassName prop (react-bootstrap#5367)
* create contentClassName prop * Pass contentClassName to modal dialog * Add test
1 parent 5c5ea8d commit dca61bd

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Modal.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface ModalProps
4444
backdropClassName?: string;
4545
animation?: boolean;
4646
dialogClassName?: string;
47+
contentClassName?: string;
4748
dialogAs?: React.ElementType;
4849
scrollable?: boolean;
4950
}
@@ -110,6 +111,11 @@ const propTypes = {
110111
*/
111112
dialogClassName: PropTypes.string,
112113

114+
/**
115+
* Add an optional extra class name to .modal-content
116+
*/
117+
contentClassName: PropTypes.string,
118+
113119
/**
114120
* A Component type that provides the modal content Markup. This is a useful
115121
* prop when you want to use your own styles and markup to create a custom
@@ -241,6 +247,7 @@ const Modal: Modal = (React.forwardRef(
241247
className,
242248
style,
243249
dialogClassName,
250+
contentClassName,
244251
children,
245252
dialogAs: Dialog,
246253
'aria-labelledby': ariaLabelledby,
@@ -477,6 +484,7 @@ const Modal: Modal = (React.forwardRef(
477484
role="document"
478485
onMouseDown={handleDialogMouseDown}
479486
className={dialogClassName}
487+
contentClassName={contentClassName}
480488
>
481489
{children}
482490
</Dialog>

src/ModalDialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ export interface ModalDialogProps
1212
size?: 'sm' | 'lg' | 'xl';
1313
centered?: boolean;
1414
scrollable?: boolean;
15+
contentClassName?: string;
1516
}
1617

1718
const propTypes = {
1819
/** @default 'modal' */
1920
bsPrefix: PropTypes.string,
21+
contentClassName: PropTypes.string,
2022

2123
/**
2224
* Render a large, extra large or small modal.
@@ -41,6 +43,7 @@ const ModalDialog = React.forwardRef<HTMLDivElement, ModalDialogProps>(
4143
{
4244
bsPrefix,
4345
className,
46+
contentClassName,
4447
centered,
4548
size,
4649
children,
@@ -64,7 +67,9 @@ const ModalDialog = React.forwardRef<HTMLDivElement, ModalDialogProps>(
6467
scrollable && `${dialogClass}-scrollable`,
6568
)}
6669
>
67-
<div className={`${bsPrefix}-content`}>{children}</div>
70+
<div className={classNames(`${bsPrefix}-content`, contentClassName)}>
71+
{children}
72+
</div>
6873
</div>
6974
);
7075
},

test/ModalSpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ describe('<Modal>', () => {
198198
).assertSingle('.modal-dialog.my-dialog');
199199
});
200200

201+
it('Should pass contentClassName to .modal-content', () => {
202+
const noOp = () => {};
203+
mount(
204+
<Modal show contentClassName="my-content" onHide={noOp}>
205+
<strong>Message</strong>
206+
</Modal>,
207+
).assertSingle('.modal-content.my-content');
208+
});
209+
201210
it('Should use dialogAs', () => {
202211
const noOp = () => {};
203212

0 commit comments

Comments
 (0)