diff --git a/components/modal/demo/basic.md b/components/modal/demo/basic.md index 2b771b9b7b..104a88ff3e 100644 --- a/components/modal/demo/basic.md +++ b/components/modal/demo/basic.md @@ -18,7 +18,7 @@ var Test = React.createClass({ showModal(e) { this.setState({ visible: true, - mousePosition:{x:e.pageX,y:e.pageY} + mousePosition: {x:e.pageX,y:e.pageY} }); }, handleOk() { diff --git a/components/modal/demo/confirm-promise.md b/components/modal/demo/confirm-promise.md index 2d58e172b6..e3f08482c7 100644 --- a/components/modal/demo/confirm-promise.md +++ b/components/modal/demo/confirm-promise.md @@ -15,8 +15,8 @@ function showConfirm(){ content: '一些解释', onOk: function() { alert('1 秒后关闭'); - return new Promise(function(resolve){ - setTimeout(resolve,1000); + return new Promise(function(resolve) { + setTimeout(resolve, 1000); }); }, onCancel: function() {} diff --git a/components/modal/demo/footer.md b/components/modal/demo/footer.md index dcc5657c39..8e2c1963ac 100644 --- a/components/modal/demo/footer.md +++ b/components/modal/demo/footer.md @@ -17,11 +17,14 @@ var Test = React.createClass({ }; }, showModal(e) { - this.setState({ visible: true,mousePosition:{x:e.pageX,y:e.pageY} }); + this.setState({ + visible: true, + mousePosition:{x:e.pageX,y:e.pageY} + }); }, handleOk() { this.setState({ loading: true }); - setTimeout(()=> { + setTimeout(() => { this.setState({ loading: false, visible: false }); }, 3000); }, @@ -39,9 +42,8 @@ var Test = React.createClass({ title="对话框标题" onOk={this.handleOk} onCancel={this.handleCancel} footer={[ , - ]}>

对话框的内容

diff --git a/components/modal/index.jsx b/components/modal/index.jsx index 59c86c0a87..1acba1d35f 100644 --- a/components/modal/index.jsx +++ b/components/modal/index.jsx @@ -4,16 +4,6 @@ function noop() { } export default React.createClass({ - getInitialState() { - return { - confirmLoading: false - }; - }, - - handleCancel() { - this.props.onCancel(); - }, - getDefaultProps() { return { prefixCls: 'ant-modal', @@ -22,6 +12,20 @@ export default React.createClass({ }; }, + getInitialState() { + return { + confirmLoading: false, + visible: this.props.visible + }; + }, + + handleCancel() { + this.props.onCancel(); + this.setState({ + visible: false + }); + }, + handleOk() { this.setState({ confirmLoading: true @@ -31,27 +35,32 @@ export default React.createClass({ componentWillReceiveProps(nextProps) { if ('visible' in nextProps) { + let newState = { + visible: nextProps.visible + }; // 隐藏后去除按钮 loading 效果 if (!nextProps.visible) { - this.setState({ - confirmLoading: false - }); + newState.confirmLoading = false; } + this.setState(newState); } }, render() { - var loadingIcon = this.state.confirmLoading ? - : ''; - var props = this.props; - var defaultFooter = [ + let loadingClass = this.state.confirmLoading ? ' ant-btn-loading' : ''; + let props = this.props; + let defaultFooter = [ , - ]; - var footer = props.footer || defaultFooter; - return ; + let footer = props.footer || defaultFooter; + let visible = this.state.visible; + return ; } });