mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 13:08:41 +08:00
Fix cancel button can not close modal
1. 关闭取消按钮的修复 2. 优化 loading 按钮的效果
This commit is contained in:
parent
58bd830f40
commit
1c5e3485e7
@ -18,7 +18,7 @@ var Test = React.createClass({
|
|||||||
showModal(e) {
|
showModal(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
visible: true,
|
visible: true,
|
||||||
mousePosition:{x:e.pageX,y:e.pageY}
|
mousePosition: {x:e.pageX,y:e.pageY}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleOk() {
|
handleOk() {
|
||||||
|
@ -15,8 +15,8 @@ function showConfirm(){
|
|||||||
content: '一些解释',
|
content: '一些解释',
|
||||||
onOk: function() {
|
onOk: function() {
|
||||||
alert('1 秒后关闭');
|
alert('1 秒后关闭');
|
||||||
return new Promise(function(resolve){
|
return new Promise(function(resolve) {
|
||||||
setTimeout(resolve,1000);
|
setTimeout(resolve, 1000);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onCancel: function() {}
|
onCancel: function() {}
|
||||||
|
@ -17,11 +17,14 @@ var Test = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
showModal(e) {
|
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() {
|
handleOk() {
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
setTimeout(()=> {
|
setTimeout(() => {
|
||||||
this.setState({ loading: false, visible: false });
|
this.setState({ loading: false, visible: false });
|
||||||
}, 3000);
|
}, 3000);
|
||||||
},
|
},
|
||||||
@ -39,9 +42,8 @@ var Test = React.createClass({
|
|||||||
title="对话框标题" onOk={this.handleOk} onCancel={this.handleCancel}
|
title="对话框标题" onOk={this.handleOk} onCancel={this.handleCancel}
|
||||||
footer={[
|
footer={[
|
||||||
<button key="back" className="ant-btn ant-btn-lg" onClick={this.handleCancel}>返 回</button>,
|
<button key="back" className="ant-btn ant-btn-lg" onClick={this.handleCancel}>返 回</button>,
|
||||||
<button key="submit" className="ant-btn ant-btn-primary ant-btn-lg" onClick={this.handleOk}>
|
<button key="submit" className={'ant-btn ant-btn-primary ant-btn-lg ' + (this.state.loading?'ant-btn-loading':'')} onClick={this.handleOk}>
|
||||||
提 交
|
提 交
|
||||||
<i className={'anticon anticon-loading'+(this.state.loading?'':'hide')}></i>
|
|
||||||
</button>
|
</button>
|
||||||
]}>
|
]}>
|
||||||
<p>对话框的内容</p>
|
<p>对话框的内容</p>
|
||||||
|
@ -4,16 +4,6 @@ function noop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default React.createClass({
|
export default React.createClass({
|
||||||
getInitialState() {
|
|
||||||
return {
|
|
||||||
confirmLoading: false
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
handleCancel() {
|
|
||||||
this.props.onCancel();
|
|
||||||
},
|
|
||||||
|
|
||||||
getDefaultProps() {
|
getDefaultProps() {
|
||||||
return {
|
return {
|
||||||
prefixCls: 'ant-modal',
|
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() {
|
handleOk() {
|
||||||
this.setState({
|
this.setState({
|
||||||
confirmLoading: true
|
confirmLoading: true
|
||||||
@ -31,27 +35,32 @@ export default React.createClass({
|
|||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if ('visible' in nextProps) {
|
if ('visible' in nextProps) {
|
||||||
|
let newState = {
|
||||||
|
visible: nextProps.visible
|
||||||
|
};
|
||||||
// 隐藏后去除按钮 loading 效果
|
// 隐藏后去除按钮 loading 效果
|
||||||
if (!nextProps.visible) {
|
if (!nextProps.visible) {
|
||||||
this.setState({
|
newState.confirmLoading = false;
|
||||||
confirmLoading: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
var loadingIcon = this.state.confirmLoading ?
|
let loadingClass = this.state.confirmLoading ? ' ant-btn-loading' : '';
|
||||||
<i className="anticon anticon-loading"></i> : '';
|
let props = this.props;
|
||||||
var props = this.props;
|
let defaultFooter = [
|
||||||
var defaultFooter = [
|
|
||||||
<button key="cancel" type="button" className="ant-btn ant-btn-lg" onClick={this.handleCancel}>取 消</button>,
|
<button key="cancel" type="button" className="ant-btn ant-btn-lg" onClick={this.handleCancel}>取 消</button>,
|
||||||
<button key="confirm" type="button" className="ant-btn ant-btn-primary ant-btn-lg" onClick={this.handleOk}>
|
<button key="confirm"
|
||||||
确 定 {loadingIcon}
|
type="button"
|
||||||
|
className={'ant-btn ant-btn-primary ant-btn-lg' + loadingClass}
|
||||||
|
onClick={this.handleOk}>
|
||||||
|
确 定
|
||||||
</button>
|
</button>
|
||||||
];
|
];
|
||||||
var footer = props.footer || defaultFooter;
|
let footer = props.footer || defaultFooter;
|
||||||
return <Dialog transitionName="zoom" onClose={props.onCancel} visible={this.state.visible}
|
let visible = this.state.visible;
|
||||||
maskAnimation="fade" width="500" footer={footer} {...props}/>;
|
return <Dialog transitionName="zoom" onClose={this.handleCancel} maskAnimation="fade"
|
||||||
|
width="500" footer={footer} {...props} visible={visible} />;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user