diff --git a/components/modal/demo/custom.md b/components/modal/demo/async.md
similarity index 78%
rename from components/modal/demo/custom.md
rename to components/modal/demo/async.md
index d5bd2993ad..7e4ffb31d5 100644
--- a/components/modal/demo/custom.md
+++ b/components/modal/demo/async.md
@@ -2,7 +2,7 @@
- order: 1
-点击确定后异步关闭对话框。
+点击确定后异步关闭对话框,例如提交表单。
---
@@ -26,11 +26,13 @@ var Test = React.createClass({
},
handleOk() {
this.setState({
- ModalText: '对话框将在两秒后关闭'
+ ModalText: '对话框将在两秒后关闭',
+ confirmLoading: true
});
setTimeout(() => {
this.setState({
- visible: false
+ visible: false,
+ confirmLoading: false
});
}, 2000);
},
@@ -46,6 +48,7 @@ var Test = React.createClass({
{this.state.ModalText}
对话框的内容
对话框的内容
对话框的内容
diff --git a/components/modal/index.jsx b/components/modal/index.jsx index 9956cc04e2..0a9f1e83fe 100644 --- a/components/modal/index.jsx +++ b/components/modal/index.jsx @@ -4,8 +4,7 @@ import { Dom } from 'rc-util'; import confirm from './confirm'; import { Button } from '../button'; -function noop() { -} +function noop() {} let mousePosition; let mousePositionEventBinded; @@ -18,14 +17,9 @@ let AntModal = React.createClass({ onCancel: noop, width: 520, transitionName: 'zoom', - maskAnimation: 'fade' - }; - }, - - getInitialState() { - return { + maskAnimation: 'fade', confirmLoading: false, - visible: this.props.visible + visible: false }; }, @@ -34,27 +28,9 @@ let AntModal = React.createClass({ }, handleOk() { - this.setState({ - confirmLoading: true - }); this.props.onOk(); }, - componentWillReceiveProps(nextProps) { - let newState = {}; - if ('visible' in nextProps) { - newState.visible = nextProps.visible; - // 隐藏后默认去除按钮 loading 效果 - if (!nextProps.visible) { - newState.confirmLoading = false; - } - } - if ('confirmLoading' in nextProps) { - newState.confirmLoading = !!nextProps.confirmLoading; - } - this.setState(newState); - }, - componentDidMount() { if (mousePositionEventBinded) { return; @@ -85,15 +61,14 @@ let AntModal = React.createClass({ ]; let footer = props.footer || defaultFooter; - let visible = this.state.visible; return ; + visible={props.visible} mousePosition={mousePosition} />; } });