Skip to content

Commit

Permalink
[added] Added an id prop, applied to the modal dialog (content) (#765)
Browse files Browse the repository at this point in the history
* Added an ID prop, applied to the modal dialog.
  • Loading branch information
YassienW authored and diasbruno committed Jul 14, 2019
1 parent d7ec04d commit c747c24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ import ReactModal from 'react-modal';
See the `Styles` section for more details.
*/
overlayClassName="ReactModal__Overlay"
/*
String id to be applied to the content div
*/
id=""
/*
String className to be applied to the modal content.
See the `Styles` section for more details.
Expand Down
7 changes: 7 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ export default () => {
});
});

it("supports id prop", () => {
const modal = renderModal({ isOpen: true, id: "id" });
mcontent(modal)
.id.includes("id")
.should.be.ok();
});

it("supports portalClassName", () => {
const modal = renderModal({
isOpen: true,
Expand Down
4 changes: 3 additions & 1 deletion src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class ModalPortal extends Component {
shouldCloseOnEsc: PropTypes.bool,
overlayRef: PropTypes.func,
contentRef: PropTypes.func,
id: PropTypes.string,
testId: PropTypes.string
};

Expand Down Expand Up @@ -328,7 +329,7 @@ export default class ModalPortal extends Component {
}, {});

render() {
const { className, overlayClassName, defaultStyles } = this.props;
const { id, className, overlayClassName, defaultStyles } = this.props;
const contentStyles = className ? {} : defaultStyles.content;
const overlayStyles = overlayClassName ? {} : defaultStyles.overlay;

Expand All @@ -341,6 +342,7 @@ export default class ModalPortal extends Component {
onMouseDown={this.handleOverlayOnMouseDown}
>
<div
id={id}
ref={this.setContentRef}
style={{ ...contentStyles, ...this.props.style.content }}
className={this.buildClassName("content", className)}
Expand Down

0 comments on commit c747c24

Please sign in to comment.