mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 01:19:45 +08:00
f465589bd6
* fix: Modal footer buttons not spaced when using href in button * fix: resolve comments
89 lines
2.1 KiB
Markdown
89 lines
2.1 KiB
Markdown
---
|
|
order: 2
|
|
title:
|
|
zh-CN: 自定义页脚
|
|
en-US: Customized Footer
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。
|
|
|
|
不需要默认确定取消按钮时,你可以把 `footer` 设为 `null`。
|
|
|
|
## en-US
|
|
|
|
A more complex example which define a customized footer button bar. The dialog will change to loading state after clicking the submit button, and when the loading is done, the modal dialog will be closed.
|
|
|
|
You could set `footer` to `null` if you don't need default footer buttons.
|
|
|
|
```jsx
|
|
import { Modal, Button } from 'antd';
|
|
|
|
class App extends React.Component {
|
|
state = {
|
|
loading: false,
|
|
visible: false,
|
|
};
|
|
|
|
showModal = () => {
|
|
this.setState({
|
|
visible: true,
|
|
});
|
|
};
|
|
|
|
handleOk = () => {
|
|
this.setState({ loading: true });
|
|
setTimeout(() => {
|
|
this.setState({ loading: false, visible: false });
|
|
}, 3000);
|
|
};
|
|
|
|
handleCancel = () => {
|
|
this.setState({ visible: false });
|
|
};
|
|
|
|
render() {
|
|
const { visible, loading } = this.state;
|
|
return (
|
|
<>
|
|
<Button type="primary" onClick={this.showModal}>
|
|
Open Modal with customized footer
|
|
</Button>
|
|
<Modal
|
|
visible={visible}
|
|
title="Title"
|
|
onOk={this.handleOk}
|
|
onCancel={this.handleCancel}
|
|
footer={[
|
|
<Button key="back" onClick={this.handleCancel}>
|
|
Return
|
|
</Button>,
|
|
<Button key="submit" type="primary" loading={loading} onClick={this.handleOk}>
|
|
Submit
|
|
</Button>,
|
|
<Button
|
|
key="link"
|
|
href="https://google.com"
|
|
type="primary"
|
|
loading={loading}
|
|
onClick={this.handleOk}
|
|
>
|
|
Search on Google
|
|
</Button>,
|
|
]}
|
|
>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
|
```
|