Skip to content

Commit

Permalink
Merged next into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
diasbruno committed Oct 6, 2017
2 parents bf9d376 + de3c039 commit d0f242b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 39 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v2.4.1 - Fri, 06 Oct 2017 13:23:42 UTC
--------------------------------------

- [4fa5628](../../commit/4fa5628) [fixed] Drag stop (mouseup) on Overlay closes Modal
- [a712d88](../../commit/a712d88) [chore] update README.md installation for react 16 support.
- [f9a2f3f](../../commit/f9a2f3f) [chore] update README.md.


v2.3.3 - Wed, 04 Oct 2017 01:59:30 UTC
--------------------------------------

Expand Down
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ Accessible modal dialog component for React.JS
[![Coverage Status](https://coveralls.io/repos/github/reactjs/react-modal/badge.svg?branch=master)](https://coveralls.io/github/reactjs/react-modal?branch=master)
![gzip size](http://img.badgesize.io/https://unpkg.com/react-modal/dist/react-modal.min.js?compression=gzip)

## React 16

A initial support for React 16 is available under the branch `next`.

Please, when open a new PR set the target branch `next` for `react-modal@3.x` and `master` for `2.x`.

Note that it can be unstable.

## Table of Contents

* [Installation](#installation)
Expand All @@ -28,12 +20,6 @@ Note that it can be unstable.

To install, you can use [npm](https://npmjs.org/) or [yarn](https://yarnpkg.com):

With React 16 support (3.0.0-rc2):

$ npm install react-modal@next
$ yarn add react-modal@next

To install the stable version (2.4.1):

$ npm install react-modal
$ yarn add react-modal
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"karma-webpack": "^2.0.4",
"mocha": "3.5.3",
"npm-run-all": "^4.1.1",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"should": "^13.1.0",
Expand All @@ -62,8 +62,8 @@
"prop-types": "^15.5.10"
},
"peerDependencies": {
"react": "^0.14.0 || ^15.0.0",
"react-dom": "^0.14.0 || ^15.0.0"
"react": "^0.14.0 || ^15.0.0 || ^16",
"react-dom": "^0.14.0 || ^15.0.0 || ^16"
},
"tags": [
"react",
Expand Down
4 changes: 2 additions & 2 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default () => {
escKeyDown(modalContent);
});

it('does not steel focus when a descendent is already focused', () => {
xit('does not steel focus when a descendent is already focused', () => {
let content;
const input = (
<input ref={(el) => { el && el.focus(); content = el; }} />
Expand Down Expand Up @@ -414,7 +414,7 @@ export default () => {
}, closeTimeoutMS);
});

it('shouldn\'t throw if forcibly unmounted during mounting', () => {
xit('shouldn\'t throw if forcibly unmounted during mounting', () => {
/* eslint-disable camelcase, react/prop-types */
class Wrapper extends Component {
constructor (props) {
Expand Down
55 changes: 36 additions & 19 deletions src/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import ModalPortal from './ModalPortal';
import * as ariaAppHider from '../helpers/ariaAppHider';
import SafeHTMLElement from '../helpers/safeHTMLElement';
import SafeHTMLElement, {
canUseDOM
} from '../helpers/safeHTMLElement';

export const portalClassName = 'ReactModalPortal';
export const bodyOpenClassName = 'ReactModal__Body--open';

const renderSubtreeIntoContainer = ReactDOM.unstable_renderSubtreeIntoContainer;
const isReact16 = ReactDOM.createPortal !== undefined;
const createPortal = isReact16 ?
ReactDOM.createPortal :
ReactDOM.unstable_renderSubtreeIntoContainer;

function getParentElement(parentSelector) {
return parentSelector();
Expand All @@ -19,16 +24,6 @@ export default class Modal extends Component {
ariaAppHider.setElement(element);
}

/* eslint-disable no-console */
static injectCSS() {
(process.env.NODE_ENV !== "production")
&& console.warn(
'React-Modal: injectCSS has been deprecated ' +
'and no longer has any effect. It will be removed in a later version'
);
}
/* eslint-enable no-console */

/* eslint-disable react/no-unused-prop-types */
static propTypes = {
isOpen: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -97,16 +92,21 @@ export default class Modal extends Component {
};

componentDidMount() {
this.node = document.createElement('div');
if (!canUseDOM) return;

if (!isReact16) {
this.node = document.createElement('div');
}
this.node.className = this.props.portalClassName;

const parent = getParentElement(this.props.parentSelector);
parent.appendChild(this.node);

this.renderPortal(this.props);
(!isReact16) && this.renderPortal(this.props);
}

componentWillReceiveProps(newProps) {
if (!canUseDOM) return;
const { isOpen } = newProps;
// Stop unnecessary renders if modal is remaining closed
if (!this.props.isOpen && !isOpen) return;
Expand All @@ -119,17 +119,18 @@ export default class Modal extends Component {
newParent.appendChild(this.node);
}

this.renderPortal(newProps);
(!isReact16) && this.renderPortal(newProps);
}

componentWillUpdate(newProps) {
if (!canUseDOM) return;
if (newProps.portalClassName !== this.props.portalClassName) {
this.node.className = newProps.portalClassName;
}
}

componentWillUnmount() {
if (!this.node || !this.portal) return;
if (!canUseDOM || !this.node || !this.portal) return;

const state = this.portal.state;
const now = Date.now();
Expand All @@ -149,18 +150,34 @@ export default class Modal extends Component {
}

removePortal = () => {
ReactDOM.unmountComponentAtNode(this.node);
(!isReact16) && ReactDOM.unmountComponentAtNode(this.node);
const parent = getParentElement(this.props.parentSelector);
parent.removeChild(this.node);
}

portalRef = ref => { this.portal = ref; }

renderPortal = props => {
this.portal = renderSubtreeIntoContainer(this, (
const portal = createPortal(this, (
<ModalPortal defaultStyles={Modal.defaultStyles} {...props} />
), this.node);
this.portalRef(portal);
}

render() {
return null;
if (!canUseDOM || !isReact16) {
return null;
}

if (!this.node && isReact16) {
this.node = document.createElement('div');
}

return createPortal(
<ModalPortal ref={this.portalRef}
defaultStyles={Modal.defaultStyles}
{...this.props} />,
this.node
);
}
}
2 changes: 2 additions & 0 deletions src/helpers/safeHTMLElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ const EE = ExecutionEnvironment;

const SafeHTMLElement = EE.canUseDOM ? window.HTMLElement : {};

export const canUseDOM = EE.canUseDOM;

export default SafeHTMLElement;

0 comments on commit d0f242b

Please sign in to comment.