From 95dd2cfb44507cca1f52232b241ed1ca97267138 Mon Sep 17 00:00:00 2001 From: Clay Diffrient Date: Fri, 7 Oct 2016 22:11:39 -0600 Subject: [PATCH] release v1.5.1 --- CHANGELOG.md | 6 ++ bower.json | 2 +- dist/react-modal.js | 119 +++++++++++++++++++++------------------- dist/react-modal.min.js | 6 +- package.json | 2 +- 5 files changed, 75 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ee0d78..538c6f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +v1.5.1 - Sat, 08 Oct 2016 04:11:39 GMT +-------------------------------------- + +- + + v1.5.0 - Sat, 08 Oct 2016 02:18:52 GMT -------------------------------------- diff --git a/bower.json b/bower.json index 27c9faca..d852763d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "react-modal", - "version": "1.5.0", + "version": "1.5.1", "homepage": "https://github.com/rackt/react-modal", "authors": [ "Ryan Florence", diff --git a/dist/react-modal.js b/dist/react-modal.js index d775273f..769ed3fe 100644 --- a/dist/react-modal.js +++ b/dist/react-modal.js @@ -6,7 +6,7 @@ else if(typeof exports === 'object') exports["ReactModal"] = factory(require("react"), require("react-dom")); else - root["ReactModal"] = factory(root["react"], root["react-dom"]); + root["ReactModal"] = factory(root["React"], root["ReactDOM"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache @@ -94,17 +94,20 @@ return /******/ (function(modules) { // webpackBootstrap content: React.PropTypes.object, overlay: React.PropTypes.object }), + portalClassName: React.PropTypes.string, appElement: React.PropTypes.instanceOf(SafeHTMLElement), onAfterOpen: React.PropTypes.func, onRequestClose: React.PropTypes.func, closeTimeoutMS: React.PropTypes.number, ariaHideApp: React.PropTypes.bool, - shouldCloseOnOverlayClick: React.PropTypes.bool + shouldCloseOnOverlayClick: React.PropTypes.bool, + role: React.PropTypes.string }, getDefaultProps: function getDefaultProps() { return { isOpen: false, + portalClassName: 'ReactModalPortal', ariaHideApp: true, closeTimeoutMS: 0, shouldCloseOnOverlayClick: true @@ -113,7 +116,7 @@ return /******/ (function(modules) { // webpackBootstrap componentDidMount: function componentDidMount() { this.node = document.createElement('div'); - this.node.className = 'ReactModalPortal'; + this.node.className = this.props.portalClassName; document.body.appendChild(this.node); this.renderPortal(this.props); }, @@ -260,6 +263,7 @@ return /******/ (function(modules) { // webpackBootstrap var ModalPortal = module.exports = React.createClass({ displayName: 'ModalPortal', + shouldClose: null, getDefaultProps: function getDefaultProps() { return { @@ -333,7 +337,10 @@ return /******/ (function(modules) { // webpackBootstrap }, focusContent: function focusContent() { - this.refs.content.focus(); + // Don't steal focus from inner elements + if (!this.contentHasFocus()) { + this.refs.content.focus(); + } }, closeWithTimeout: function closeWithTimeout() { @@ -363,17 +370,25 @@ return /******/ (function(modules) { // webpackBootstrap } }, - handleOverlayClick: function handleOverlayClick(event) { - var node = event.target; - - while (node) { - if (node === this.refs.content) return; - node = node.parentNode; + handleOverlayMouseDown: function handleOverlayMouseDown(event) { + if (this.shouldClose === null) { + this.shouldClose = true; } + }, - if (this.props.shouldCloseOnOverlayClick) { + handleOverlayMouseUp: function handleOverlayMouseUp(event) { + if (this.shouldClose && this.props.shouldCloseOnOverlayClick) { if (this.ownerHandlesClose()) this.requestClose(event);else this.focusContent(); } + this.shouldClose = null; + }, + + handleContentMouseDown: function handleContentMouseDown(event) { + this.shouldClose = false; + }, + + handleContentMouseUp: function handleContentMouseUp(event) { + this.shouldClose = false; }, requestClose: function requestClose(event) { @@ -388,6 +403,10 @@ return /******/ (function(modules) { // webpackBootstrap return !this.props.isOpen && !this.state.beforeClose; }, + contentHasFocus: function contentHasFocus() { + return document.activeElement === this.refs.content || this.refs.content.contains(document.activeElement); + }, + buildClassName: function buildClassName(which, additional) { var className = CLASS_NAMES[which].base; if (this.state.afterOpen) className += ' ' + CLASS_NAMES[which].afterOpen; @@ -403,13 +422,17 @@ return /******/ (function(modules) { // webpackBootstrap ref: "overlay", className: this.buildClassName('overlay', this.props.overlayClassName), style: Assign({}, overlayStyles, this.props.style.overlay || {}), - onClick: this.handleOverlayClick + onMouseDown: this.handleOverlayMouseDown, + onMouseUp: this.handleOverlayMouseUp }, div({ ref: "content", style: Assign({}, contentStyles, this.props.style.content || {}), className: this.buildClassName('content', this.props.className), tabIndex: "-1", - onKeyDown: this.handleKeyDown + onKeyDown: this.handleKeyDown, + onMouseDown: this.handleContentMouseDown, + onMouseUp: this.handleContentMouseUp, + role: "dialog" }, this.props.children)); } }); @@ -437,8 +460,8 @@ return /******/ (function(modules) { // webpackBootstrap } // need to see how jQuery shims document.on('focusin') so we don't need the // setTimeout, firefox doesn't support focusin, if it did, we could focus - // the element outside of a setTimeout. Side-effect of this implementation - // is that the document.body gets focus, and then we focus our element right + // the element outside of a setTimeout. Side-effect of this implementation + // is that the document.body gets focus, and then we focus our element right // after, seems fine. setTimeout(function () { if (modalElement.contains(document.activeElement)) return; @@ -1107,12 +1130,12 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { /** - * lodash 3.0.8 (Custom Build) + * lodash (Custom Build) * Build: `lodash modularize exports="npm" -o ./` - * Copyright 2012-2016 The Dojo Foundation + * Copyright jQuery Foundation and other contributors + * Released under MIT license * Based on Underscore.js 1.8.3 - * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - * Available under MIT license + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */ /** Used as references for various `Number` constants. */ @@ -1130,7 +1153,8 @@ return /******/ (function(modules) { // webpackBootstrap var hasOwnProperty = objectProto.hasOwnProperty; /** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; @@ -1138,39 +1162,16 @@ return /******/ (function(modules) { // webpackBootstrap /** Built-in value references. */ var propertyIsEnumerable = objectProto.propertyIsEnumerable; - /** - * The base implementation of `_.property` without support for deep paths. - * - * @private - * @param {string} key The key of the property to get. - * @returns {Function} Returns the new function. - */ - function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; - }; - } - - /** - * Gets the "length" property value of `object`. - * - * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) - * that affects Safari on at least iOS 8.1-8.3 ARM64. - * - * @private - * @param {Object} object The object to query. - * @returns {*} Returns the "length" value. - */ - var getLength = baseProperty('length'); - /** * Checks if `value` is likely an `arguments` object. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + * else `false`. * @example * * _.isArguments(function() { return arguments; }()); @@ -1180,7 +1181,7 @@ return /******/ (function(modules) { // webpackBootstrap * // => false */ function isArguments(value) { - // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. + // Safari 8.1 makes `arguments.callee` enumerable in strict mode. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); } @@ -1192,6 +1193,7 @@ return /******/ (function(modules) { // webpackBootstrap * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is array-like, else `false`. @@ -1210,7 +1212,7 @@ return /******/ (function(modules) { // webpackBootstrap * // => false */ function isArrayLike(value) { - return value != null && isLength(getLength(value)) && !isFunction(value); + return value != null && isLength(value.length) && !isFunction(value); } /** @@ -1219,9 +1221,11 @@ return /******/ (function(modules) { // webpackBootstrap * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. * @example * * _.isArrayLikeObject([1, 2, 3]); @@ -1245,9 +1249,10 @@ return /******/ (function(modules) { // webpackBootstrap * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); @@ -1258,8 +1263,7 @@ return /******/ (function(modules) { // webpackBootstrap */ function isFunction(value) { // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8 which returns 'object' for typed array and weak map constructors, - // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. + // in Safari 8-9 which returns 'object' for typed array and other constructors. var tag = isObject(value) ? objectToString.call(value) : ''; return tag == funcTag || tag == genTag; } @@ -1267,10 +1271,12 @@ return /******/ (function(modules) { // webpackBootstrap /** * Checks if `value` is a valid array-like length. * - * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. @@ -1294,11 +1300,13 @@ return /******/ (function(modules) { // webpackBootstrap } /** - * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. - * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. @@ -1327,6 +1335,7 @@ return /******/ (function(modules) { // webpackBootstrap * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is object-like, else `false`. diff --git a/dist/react-modal.min.js b/dist/react-modal.min.js index c7287b7d..572aa830 100644 --- a/dist/react-modal.min.js +++ b/dist/react-modal.min.js @@ -1,9 +1,9 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports.ReactModal=t(require("react"),require("react-dom")):e.ReactModal=t(e.react,e["react-dom"])}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="/",t(0)}([function(e,t,n){"use strict";e.exports=n(1)},function(e,t,n){"use strict";var o=n(2),r=n(3),i=n(4),s=o.createFactory(n(5)),u=n(20),c=n(21),a=n(3).unstable_renderSubtreeIntoContainer,l=n(9),f=i.canUseDOM?window.HTMLElement:{},p=i.canUseDOM?document.body:{appendChild:function(){}},d=o.createClass({displayName:"Modal",statics:{setAppElement:function(e){p=u.setElement(e)},injectCSS:function(){console.warn("React-Modal: injectCSS has been deprecated and no longer has any effect. It will be removed in a later version")}},propTypes:{isOpen:o.PropTypes.bool.isRequired,style:o.PropTypes.shape({content:o.PropTypes.object,overlay:o.PropTypes.object}),appElement:o.PropTypes.instanceOf(f),onAfterOpen:o.PropTypes.func,onRequestClose:o.PropTypes.func,closeTimeoutMS:o.PropTypes.number,ariaHideApp:o.PropTypes.bool,shouldCloseOnOverlayClick:o.PropTypes.bool},getDefaultProps:function(){return{isOpen:!1,ariaHideApp:!0,closeTimeoutMS:0,shouldCloseOnOverlayClick:!0}},componentDidMount:function(){this.node=document.createElement("div"),this.node.className="ReactModalPortal",document.body.appendChild(this.node),this.renderPortal(this.props)},componentWillReceiveProps:function(e){this.renderPortal(e)},componentWillUnmount:function(){r.unmountComponentAtNode(this.node),document.body.removeChild(this.node),c(document.body).remove("ReactModal__Body--open")},renderPortal:function(e){e.isOpen?c(document.body).add("ReactModal__Body--open"):c(document.body).remove("ReactModal__Body--open"),e.ariaHideApp&&u.toggle(e.isOpen,e.appElement),this.portal=a(this,s(l({},e,{defaultStyles:d.defaultStyles})),this.node)},render:function(){return o.DOM.noscript()}});d.defaultStyles={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.75)"},content:{position:"absolute",top:"40px",left:"40px",right:"40px",bottom:"40px",border:"1px solid #ccc",background:"#fff",overflow:"auto",WebkitOverflowScrolling:"touch",borderRadius:"4px",outline:"none",padding:"20px"}},e.exports=d},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){var o;/*! +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports.ReactModal=t(require("react"),require("react-dom")):e.ReactModal=t(e.React,e.ReactDOM)}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="/",t(0)}([function(e,t,n){"use strict";e.exports=n(1)},function(e,t,n){"use strict";var o=n(2),r=n(3),s=n(4),i=o.createFactory(n(5)),u=n(20),c=n(21),l=n(3).unstable_renderSubtreeIntoContainer,a=n(9),f=s.canUseDOM?window.HTMLElement:{},p=s.canUseDOM?document.body:{appendChild:function(){}},d=o.createClass({displayName:"Modal",statics:{setAppElement:function(e){p=u.setElement(e)},injectCSS:function(){console.warn("React-Modal: injectCSS has been deprecated and no longer has any effect. It will be removed in a later version")}},propTypes:{isOpen:o.PropTypes.bool.isRequired,style:o.PropTypes.shape({content:o.PropTypes.object,overlay:o.PropTypes.object}),portalClassName:o.PropTypes.string,appElement:o.PropTypes.instanceOf(f),onAfterOpen:o.PropTypes.func,onRequestClose:o.PropTypes.func,closeTimeoutMS:o.PropTypes.number,ariaHideApp:o.PropTypes.bool,shouldCloseOnOverlayClick:o.PropTypes.bool,role:o.PropTypes.string},getDefaultProps:function(){return{isOpen:!1,portalClassName:"ReactModalPortal",ariaHideApp:!0,closeTimeoutMS:0,shouldCloseOnOverlayClick:!0}},componentDidMount:function(){this.node=document.createElement("div"),this.node.className=this.props.portalClassName,document.body.appendChild(this.node),this.renderPortal(this.props)},componentWillReceiveProps:function(e){this.renderPortal(e)},componentWillUnmount:function(){r.unmountComponentAtNode(this.node),document.body.removeChild(this.node),c(document.body).remove("ReactModal__Body--open")},renderPortal:function(e){e.isOpen?c(document.body).add("ReactModal__Body--open"):c(document.body).remove("ReactModal__Body--open"),e.ariaHideApp&&u.toggle(e.isOpen,e.appElement),this.portal=l(this,i(a({},e,{defaultStyles:d.defaultStyles})),this.node)},render:function(){return o.DOM.noscript()}});d.defaultStyles={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.75)"},content:{position:"absolute",top:"40px",left:"40px",right:"40px",bottom:"40px",border:"1px solid #ccc",background:"#fff",overflow:"auto",WebkitOverflowScrolling:"touch",borderRadius:"4px",outline:"none",padding:"20px"}},e.exports=d},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){var o;/*! Copyright (c) 2015 Jed Watson. Based on code that is Copyright 2013-2015, Facebook, Inc. All rights reserved. */ -!function(){"use strict";var r=!("undefined"==typeof window||!window.document||!window.document.createElement),i={canUseDOM:r,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:r&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:r&&!!window.screen};o=function(){return i}.call(t,n,t,e),!(void 0!==o&&(e.exports=o))}()},function(e,t,n){"use strict";var o=n(2),r=o.DOM.div,i=n(6),s=n(8),u=n(9),c={overlay:{base:"ReactModal__Overlay",afterOpen:"ReactModal__Overlay--after-open",beforeClose:"ReactModal__Overlay--before-close"},content:{base:"ReactModal__Content",afterOpen:"ReactModal__Content--after-open",beforeClose:"ReactModal__Content--before-close"}};e.exports=o.createClass({displayName:"ModalPortal",getDefaultProps:function(){return{style:{overlay:{},content:{}}}},getInitialState:function(){return{afterOpen:!1,beforeClose:!1}},componentDidMount:function(){this.props.isOpen&&(this.setFocusAfterRender(!0),this.open())},componentWillUnmount:function(){clearTimeout(this.closeTimer)},componentWillReceiveProps:function(e){!this.props.isOpen&&e.isOpen?(this.setFocusAfterRender(!0),this.open()):this.props.isOpen&&!e.isOpen&&this.close()},componentDidUpdate:function(){this.focusAfterRender&&(this.focusContent(),this.setFocusAfterRender(!1))},setFocusAfterRender:function(e){this.focusAfterRender=e},open:function(){this.state.afterOpen&&this.state.beforeClose?(clearTimeout(this.closeTimer),this.setState({beforeClose:!1})):(i.setupScopedFocus(this.node),i.markForFocusLater(),this.setState({isOpen:!0},function(){this.setState({afterOpen:!0}),this.props.isOpen&&this.props.onAfterOpen&&this.props.onAfterOpen()}.bind(this)))},close:function(){this.ownerHandlesClose()&&(this.props.closeTimeoutMS>0?this.closeWithTimeout():this.closeWithoutTimeout())},focusContent:function(){this.refs.content.focus()},closeWithTimeout:function(){this.setState({beforeClose:!0},function(){this.closeTimer=setTimeout(this.closeWithoutTimeout,this.props.closeTimeoutMS)}.bind(this))},closeWithoutTimeout:function(){this.setState({beforeClose:!1,isOpen:!1,afterOpen:!1},this.afterClose)},afterClose:function(){i.returnFocus(),i.teardownScopedFocus()},handleKeyDown:function(e){9==e.keyCode&&s(this.refs.content,e),27==e.keyCode&&(e.preventDefault(),this.requestClose(e))},handleOverlayClick:function(e){for(var t=e.target;t;){if(t===this.refs.content)return;t=t.parentNode}this.props.shouldCloseOnOverlayClick&&(this.ownerHandlesClose()?this.requestClose(e):this.focusContent())},requestClose:function(e){this.ownerHandlesClose()&&this.props.onRequestClose(e)},ownerHandlesClose:function(){return this.props.onRequestClose},shouldBeClosed:function(){return!this.props.isOpen&&!this.state.beforeClose},buildClassName:function(e,t){var n=c[e].base;return this.state.afterOpen&&(n+=" "+c[e].afterOpen),this.state.beforeClose&&(n+=" "+c[e].beforeClose),t?n+" "+t:n},render:function(){var e=this.props.className?{}:this.props.defaultStyles.content,t=this.props.overlayClassName?{}:this.props.defaultStyles.overlay;return this.shouldBeClosed()?r():r({ref:"overlay",className:this.buildClassName("overlay",this.props.overlayClassName),style:u({},t,this.props.style.overlay||{}),onClick:this.handleOverlayClick},r({ref:"content",style:u({},e,this.props.style.content||{}),className:this.buildClassName("content",this.props.className),tabIndex:"-1",onKeyDown:this.handleKeyDown},this.props.children))}})},function(e,t,n){"use strict";function o(e){c=!0}function r(e){if(c){if(c=!1,!s)return;setTimeout(function(){if(!s.contains(document.activeElement)){var e=i(s)[0]||s;e.focus()}},0)}}var i=n(7),s=null,u=null,c=!1;t.markForFocusLater=function(){u=document.activeElement},t.returnFocus=function(){try{u.focus()}catch(e){console.warn("You tried to return focus to "+u+" but it is not in the DOM anymore")}u=null},t.setupScopedFocus=function(e){s=e,window.addEventListener?(window.addEventListener("blur",o,!1),document.addEventListener("focus",r,!0)):(window.attachEvent("onBlur",o),document.attachEvent("onFocus",r))},t.teardownScopedFocus=function(){s=null,window.addEventListener?(window.removeEventListener("blur",o),document.removeEventListener("focus",r)):(window.detachEvent("onBlur",o),document.detachEvent("onFocus",r))}},function(e,t){"use strict";/*! +!function(){"use strict";var r=!("undefined"==typeof window||!window.document||!window.document.createElement),s={canUseDOM:r,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:r&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:r&&!!window.screen};o=function(){return s}.call(t,n,t,e),!(void 0!==o&&(e.exports=o))}()},function(e,t,n){"use strict";var o=n(2),r=o.DOM.div,s=n(6),i=n(8),u=n(9),c={overlay:{base:"ReactModal__Overlay",afterOpen:"ReactModal__Overlay--after-open",beforeClose:"ReactModal__Overlay--before-close"},content:{base:"ReactModal__Content",afterOpen:"ReactModal__Content--after-open",beforeClose:"ReactModal__Content--before-close"}};e.exports=o.createClass({displayName:"ModalPortal",shouldClose:null,getDefaultProps:function(){return{style:{overlay:{},content:{}}}},getInitialState:function(){return{afterOpen:!1,beforeClose:!1}},componentDidMount:function(){this.props.isOpen&&(this.setFocusAfterRender(!0),this.open())},componentWillUnmount:function(){clearTimeout(this.closeTimer)},componentWillReceiveProps:function(e){!this.props.isOpen&&e.isOpen?(this.setFocusAfterRender(!0),this.open()):this.props.isOpen&&!e.isOpen&&this.close()},componentDidUpdate:function(){this.focusAfterRender&&(this.focusContent(),this.setFocusAfterRender(!1))},setFocusAfterRender:function(e){this.focusAfterRender=e},open:function(){this.state.afterOpen&&this.state.beforeClose?(clearTimeout(this.closeTimer),this.setState({beforeClose:!1})):(s.setupScopedFocus(this.node),s.markForFocusLater(),this.setState({isOpen:!0},function(){this.setState({afterOpen:!0}),this.props.isOpen&&this.props.onAfterOpen&&this.props.onAfterOpen()}.bind(this)))},close:function(){this.ownerHandlesClose()&&(this.props.closeTimeoutMS>0?this.closeWithTimeout():this.closeWithoutTimeout())},focusContent:function(){this.contentHasFocus()||this.refs.content.focus()},closeWithTimeout:function(){this.setState({beforeClose:!0},function(){this.closeTimer=setTimeout(this.closeWithoutTimeout,this.props.closeTimeoutMS)}.bind(this))},closeWithoutTimeout:function(){this.setState({beforeClose:!1,isOpen:!1,afterOpen:!1},this.afterClose)},afterClose:function(){s.returnFocus(),s.teardownScopedFocus()},handleKeyDown:function(e){9==e.keyCode&&i(this.refs.content,e),27==e.keyCode&&(e.preventDefault(),this.requestClose(e))},handleOverlayMouseDown:function(e){null===this.shouldClose&&(this.shouldClose=!0)},handleOverlayMouseUp:function(e){this.shouldClose&&this.props.shouldCloseOnOverlayClick&&(this.ownerHandlesClose()?this.requestClose(e):this.focusContent()),this.shouldClose=null},handleContentMouseDown:function(e){this.shouldClose=!1},handleContentMouseUp:function(e){this.shouldClose=!1},requestClose:function(e){this.ownerHandlesClose()&&this.props.onRequestClose(e)},ownerHandlesClose:function(){return this.props.onRequestClose},shouldBeClosed:function(){return!this.props.isOpen&&!this.state.beforeClose},contentHasFocus:function(){return document.activeElement===this.refs.content||this.refs.content.contains(document.activeElement)},buildClassName:function(e,t){var n=c[e].base;return this.state.afterOpen&&(n+=" "+c[e].afterOpen),this.state.beforeClose&&(n+=" "+c[e].beforeClose),t?n+" "+t:n},render:function(){var e=this.props.className?{}:this.props.defaultStyles.content,t=this.props.overlayClassName?{}:this.props.defaultStyles.overlay;return this.shouldBeClosed()?r():r({ref:"overlay",className:this.buildClassName("overlay",this.props.overlayClassName),style:u({},t,this.props.style.overlay||{}),onMouseDown:this.handleOverlayMouseDown,onMouseUp:this.handleOverlayMouseUp},r({ref:"content",style:u({},e,this.props.style.content||{}),className:this.buildClassName("content",this.props.className),tabIndex:"-1",onKeyDown:this.handleKeyDown,onMouseDown:this.handleContentMouseDown,onMouseUp:this.handleContentMouseUp,role:"dialog"},this.props.children))}})},function(e,t,n){"use strict";function o(e){c=!0}function r(e){if(c){if(c=!1,!i)return;setTimeout(function(){if(!i.contains(document.activeElement)){var e=s(i)[0]||i;e.focus()}},0)}}var s=n(7),i=null,u=null,c=!1;t.markForFocusLater=function(){u=document.activeElement},t.returnFocus=function(){try{u.focus()}catch(e){console.warn("You tried to return focus to "+u+" but it is not in the DOM anymore")}u=null},t.setupScopedFocus=function(e){i=e,window.addEventListener?(window.addEventListener("blur",o,!1),document.addEventListener("focus",r,!0)):(window.attachEvent("onBlur",o),document.attachEvent("onFocus",r))},t.teardownScopedFocus=function(){i=null,window.addEventListener?(window.removeEventListener("blur",o),document.removeEventListener("focus",r)):(window.detachEvent("onBlur",o),document.detachEvent("onFocus",r))}},function(e,t){"use strict";/*! * Adapted from jQuery UI core * * http://jqueryui.com @@ -14,4 +14,4 @@ * * http://api.jqueryui.com/category/ui-core/ */ -function n(e,t){var n=e.nodeName.toLowerCase();return(/input|select|textarea|button|object/.test(n)?!e.disabled:"a"===n?e.href||t:t)&&r(e)}function o(e){return e.offsetWidth<=0&&e.offsetHeight<=0||"none"===e.style.display}function r(e){for(;e&&e!==document.body;){if(o(e))return!1;e=e.parentNode}return!0}function i(e){var t=e.getAttribute("tabindex");null===t&&(t=void 0);var o=isNaN(t);return(o||t>=0)&&n(e,!o)}function s(e){return[].slice.call(e.querySelectorAll("*"),0).filter(function(e){return i(e)})}e.exports=s},function(e,t,n){"use strict";var o=n(7);e.exports=function(e,t){var n=o(e);if(!n.length)return void t.preventDefault();var r=n[t.shiftKey?0:n.length-1],i=r===document.activeElement||e===document.activeElement;if(i){t.preventDefault();var s=n[t.shiftKey?n.length-1:0];s.focus()}}},function(e,t,n){function o(e,t,n){for(var o=-1,r=s(t),i=r.length;++o-1&&e%1==0&&t>e}function s(e){return"number"==typeof e&&e>-1&&e%1==0&&m>=e}function u(e){for(var t=a(e),n=t.length,o=n&&e.length,r=!!o&&s(o)&&(p(e)||f(e)),u=-1,c=[];++u0;++o-1&&e%1==0&&l>=e}function c(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function a(e){return!!e&&"object"==typeof e}var l=9007199254740991,f="[object Arguments]",p="[object Function]",d="[object GeneratorFunction]",h=Object.prototype,v=h.hasOwnProperty,y=h.toString,m=h.propertyIsEnumerable,b=n("length");e.exports=o},function(e,t){function n(e){return!!e&&"object"==typeof e}function o(e,t){var n=null==e?void 0:e[t];return u(n)?n:void 0}function r(e){return"number"==typeof e&&e>-1&&e%1==0&&m>=e}function i(e){return s(e)&&h.call(e)==a}function s(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function u(e){return null==e?!1:i(e)?v.test(p.call(e)):n(e)&&l.test(e)}var c="[object Array]",a="[object Function]",l=/^\[object .+?Constructor\]$/,f=Object.prototype,p=Function.prototype.toString,d=f.hasOwnProperty,h=f.toString,v=RegExp("^"+p.call(d).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),y=o(Array,"isArray"),m=9007199254740991,b=y||function(e){return n(e)&&r(e.length)&&h.call(e)==c};e.exports=b},function(e,t,n){function o(e){return s(function(t,n){var o=-1,s=null==t?0:n.length,u=s>2?n[s-2]:void 0,c=s>2?n[2]:void 0,a=s>1?n[s-1]:void 0;for("function"==typeof u?(u=r(u,a,5),s-=2):(u="function"==typeof a?a:void 0,s-=u?1:0),c&&i(n[0],n[1],c)&&(u=3>s?void 0:u,s=1);++o-1&&e%1==0&&t>e}function i(e,t,n){if(!u(n))return!1;var i=typeof t;if("number"==i?o(n)&&r(t,n.length):"string"==i&&t in n){var s=n[t];return e===e?e===s:s!==s}return!1}function s(e){return"number"==typeof e&&e>-1&&e%1==0&&a>=e}function u(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}var c=/^\d+$/,a=9007199254740991,l=n("length");e.exports=i},function(e,t){function n(e,t){if("function"!=typeof e)throw new TypeError(o);return t=r(void 0===t?e.length-1:+t||0,0),function(){for(var n=arguments,o=-1,i=r(n.length-t,0),s=Array(i);++on;n++)if(e[n]===t)return n;return-1}function o(e){if(!(this instanceof o))return new o(e);e||(e={}),e.nodeType&&(e={el:e}),this.opts=e,this.el=e.el||document.body,"object"!=typeof this.el&&(this.el=document.querySelector(this.el))}e.exports=function(e){return new o(e)},o.prototype.add=function(e){var t=this.el;if(t){if(""===t.className)return t.className=e;var o=t.className.split(" ");return n(o,e)>-1?o:(o.push(e),t.className=o.join(" "),o)}},o.prototype.remove=function(e){var t=this.el;if(t&&""!==t.className){var o=t.className.split(" "),r=n(o,e);return r>-1&&o.splice(r,1),t.className=o.join(" "),o}},o.prototype.has=function(e){var t=this.el;if(t){var o=t.className.split(" ");return n(o,e)>-1}},o.prototype.toggle=function(e){var t=this.el;t&&(this.has(e)?this.remove(e):this.add(e))}}])}); \ No newline at end of file +function n(e,t){var n=e.nodeName.toLowerCase();return(/input|select|textarea|button|object/.test(n)?!e.disabled:"a"===n?e.href||t:t)&&r(e)}function o(e){return e.offsetWidth<=0&&e.offsetHeight<=0||"none"===e.style.display}function r(e){for(;e&&e!==document.body;){if(o(e))return!1;e=e.parentNode}return!0}function s(e){var t=e.getAttribute("tabindex");null===t&&(t=void 0);var o=isNaN(t);return(o||t>=0)&&n(e,!o)}function i(e){return[].slice.call(e.querySelectorAll("*"),0).filter(function(e){return s(e)})}e.exports=i},function(e,t,n){"use strict";var o=n(7);e.exports=function(e,t){var n=o(e);if(!n.length)return void t.preventDefault();var r=n[t.shiftKey?0:n.length-1],s=r===document.activeElement||e===document.activeElement;if(s){t.preventDefault();var i=n[t.shiftKey?n.length-1:0];i.focus()}}},function(e,t,n){function o(e,t,n){for(var o=-1,r=i(t),s=r.length;++o-1&&e%1==0&&e-1&&e%1==0&&e<=m}function u(e){for(var t=l(e),n=t.length,o=n&&e.length,r=!!o&&i(o)&&(p(e)||f(e)),u=-1,c=[];++u0;++o-1&&e%1==0&&e<=l}function u(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function c(e){return!!e&&"object"==typeof e}var l=9007199254740991,a="[object Arguments]",f="[object Function]",p="[object GeneratorFunction]",d=Object.prototype,h=d.hasOwnProperty,v=d.toString,y=d.propertyIsEnumerable;e.exports=n},function(e,t){function n(e){return!!e&&"object"==typeof e}function o(e,t){var n=null==e?void 0:e[t];return u(n)?n:void 0}function r(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=m}function s(e){return i(e)&&h.call(e)==l}function i(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function u(e){return null!=e&&(s(e)?v.test(p.call(e)):n(e)&&a.test(e))}var c="[object Array]",l="[object Function]",a=/^\[object .+?Constructor\]$/,f=Object.prototype,p=Function.prototype.toString,d=f.hasOwnProperty,h=f.toString,v=RegExp("^"+p.call(d).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),y=o(Array,"isArray"),m=9007199254740991,b=y||function(e){return n(e)&&r(e.length)&&h.call(e)==c};e.exports=b},function(e,t,n){function o(e){return i(function(t,n){var o=-1,i=null==t?0:n.length,u=i>2?n[i-2]:void 0,c=i>2?n[2]:void 0,l=i>1?n[i-1]:void 0;for("function"==typeof u?(u=r(u,l,5),i-=2):(u="function"==typeof l?l:void 0,i-=u?1:0),c&&s(n[0],n[1],c)&&(u=i<3?void 0:u,i=1);++o-1&&e%1==0&&e-1&&e%1==0&&e<=l}function u(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}var c=/^\d+$/,l=9007199254740991,a=n("length");e.exports=s},function(e,t){function n(e,t){if("function"!=typeof e)throw new TypeError(o);return t=r(void 0===t?e.length-1:+t||0,0),function(){for(var n=arguments,o=-1,s=r(n.length-t,0),i=Array(s);++o-1?o:(o.push(e),t.className=o.join(" "),o)}},o.prototype.remove=function(e){var t=this.el;if(t&&""!==t.className){var o=t.className.split(" "),r=n(o,e);return r>-1&&o.splice(r,1),t.className=o.join(" "),o}},o.prototype.has=function(e){var t=this.el;if(t){var o=t.className.split(" ");return n(o,e)>-1}},o.prototype.toggle=function(e){var t=this.el;t&&(this.has(e)?this.remove(e):this.add(e))}}])}); \ No newline at end of file diff --git a/package.json b/package.json index bfc7bfb1..1b0b0bb4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-modal", - "version": "1.5.0", + "version": "1.5.1", "description": "Accessible modal dialog component for React.JS", "main": "./lib/index", "repository": {