Skip to content

Commit 31088c4

Browse files
Merge pull request #767 from interactivellama/modal-portal-class
Add Modal portal className
2 parents b1f7d0e + d74582c commit 31088c4

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

components/modal/index.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const propTypes = {
3333
*/
3434
children: PropTypes.node.isRequired,
3535
/**
36-
* Custom CSS classes for the modal's container.
36+
* Custom CSS classes for the modal's container. This is the element with `.slds-modal__container`. Use `classNames` [API](https://github.com/JedWatson/classnames).
3737
*/
3838
containerClassName: PropTypes.oneOfType([
3939
PropTypes.array,
4040
PropTypes.object,
4141
PropTypes.string]),
4242
/**
43-
* Custom CSS classes for the modal's body. This is the element that has overflow rules and should be used to set a static height if desired.
43+
* Custom CSS classes for the modal's body. This is the element that has overflow rules and should be used to set a static height if desired. Use `classNames` [API](https://github.com/JedWatson/classnames).
4444
*/
4545
contentClassName: PropTypes.oneOfType([
4646
PropTypes.array,
@@ -75,13 +75,23 @@ const propTypes = {
7575
*/
7676
header: PropTypes.node,
7777
/**
78-
* Adds CSS classes to the container surrounding the modal header and the close button.
78+
* Adds CSS classes to the container surrounding the modal header and the close button. Use `classNames` [API](https://github.com/JedWatson/classnames).
7979
*/
80-
headerClassName: PropTypes.node,
80+
headerClassName: PropTypes.oneOfType([
81+
PropTypes.array,
82+
PropTypes.object,
83+
PropTypes.string]),
8184
/**
8285
* Forces the modal to be open or closed.
8386
*/
8487
isOpen: PropTypes.bool.isRequired,
88+
/**
89+
* Custom CSS classes for the portal DOM node. This node is a direct descendant of the `body` and is the parent of `ReactModal__Overlay`. Use `classNames` [API](https://github.com/JedWatson/classnames).
90+
*/
91+
portalClassName: PropTypes.oneOfType([
92+
PropTypes.array,
93+
PropTypes.object,
94+
PropTypes.string]),
8595
/**
8696
* Styles the modal as a prompt.
8797
*/
@@ -350,6 +360,7 @@ class Modal extends React.Component {
350360
isOpen={this.props.isOpen}
351361
onRequestClose={this.closeModal}
352362
style={customStyles}
363+
portalClassName={classNames('ReactModalPortal', this.props.portalClassName)}
353364
>
354365
{this.getModal()}
355366
</ReactModal>

stories/modal/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ storiesOf(MODAL, module)
135135
tagline: 'Enter in details below',
136136
title: 'New Opportunity',
137137
children: modalContent,
138-
onRequestClose: action('modal closed')
138+
onRequestClose: action('modal closed'),
139+
portalClassName: 'portal-class-name-test'
139140
}))
140141
.add('Small with footer', () => getModal({
141142
isOpen: true,

tests/modal/modal.test.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ describe('SLDSModal: ', function () {
4848
containerClassName: 'container-class-name-test',
4949
contentClassName: 'content-class-name-test',
5050
contentStyle: { height: '500px' },
51-
isOpen: true
51+
isOpen: true,
52+
portalClassName: 'portal-class-name-test'
5253
});
5354
});
5455

55-
it('has correct containerClassName, contentClassName, and contentStyle', () => {
56+
it('has correct containerClassName, contentClassName, contentStyle, and portalClassName', () => {
5657
const modalContainer = getModalNode(document.body).querySelector('.slds-modal__container.container-class-name-test');
5758
expect(modalContainer).to.exist;
5859
const modalContent = getModalNode(document.body).querySelector('.slds-modal__content.content-class-name-test');
5960
expect(modalContent).to.exist;
6061
expect(modalContent.style.height).to.equal('500px');
62+
const modalPortal = document.querySelector('body > .portal-class-name-test');
63+
expect(modalPortal).to.exist;
6164
});
6265
});
6366

0 commit comments

Comments
 (0)