Popconfirm 气泡确认框
点击元素,弹出气泡式的确认框。
何时使用#
目标元素的操作需要用户进一步的确认时,在目标元素附近弹出浮层提示,询问用户。
和 confirm
弹出的全屏居中模态对话框相比,交互形式更轻量。
API#
参数 |
说明 |
类型 |
默认值 |
placement |
气泡框位置,可选 top/left/right/bottom |
string |
top |
title |
确认框的描述 |
string |
无 |
onConfirm |
点击确认的回调 |
function |
无 |
onCancel |
卡片内容 |
function |
无 |
okText |
确认按钮文字 |
String |
确定 |
cancelText |
取消按钮文字 |
String |
取消 |
代码演示
import { Popconfirm, message } from 'antd';
function confirm() {
message.success('点击了确定');
}
function cancel() {
message.error('点击了取消');
}
ReactDOM.render(
<Popconfirm title="确定要删除这个任务吗?" onConfirm={confirm} onCancel={cancel}>
<a href="#">删除</a>
</Popconfirm>
, mountNode);
import { Popconfirm } from 'antd';
ReactDOM.render(
<Popconfirm title="Are you sure?" okText="Yes" cancelText="No">
<a href="#">Delete</a>
</Popconfirm>
, mountNode);
import { Popconfirm, message, Button } from 'antd';
const text = '确定要删除这个任务吗?';
function confirm() {
message.info('点击了确定');
}
ReactDOM.render(<div>
<div style={{marginLeft: 60}}>
<Popconfirm placement="topLeft" title={text} onConfirm={confirm}>
<Button>上左</Button>
</Popconfirm>
<Popconfirm placement="top" title={text} onConfirm={confirm}>
<Button>上边</Button>
</Popconfirm>
<Popconfirm placement="topRight" title={text} onConfirm={confirm}>
<Button>上右</Button>
</Popconfirm>
</div>
<div style={{width: 60, float: 'left'}}>
<Popconfirm placement="leftTop" title={text} onConfirm={confirm}>
<Button>左上</Button>
</Popconfirm>
<Popconfirm placement="left" title={text} onConfirm={confirm}>
<Button>左边</Button>
</Popconfirm>
<Popconfirm placement="leftBottom" title={text} onConfirm={confirm}>
<Button>左下</Button>
</Popconfirm>
</div>
<div style={{width: 60, marginLeft: 252}}>
<Popconfirm placement="rightTop" title={text} onConfirm={confirm}>
<Button>右上</Button>
</Popconfirm>
<Popconfirm placement="right" title={text} onConfirm={confirm}>
<Button>右边</Button>
</Popconfirm>
<Popconfirm placement="rightBottom" title={text} onConfirm={confirm}>
<Button>右下</Button>
</Popconfirm>
</div>
<div style={{marginLeft: 60, clear: 'both'}}>
<Popconfirm placement="bottomLeft" title={text} onConfirm={confirm}>
<Button>下左</Button>
</Popconfirm>
<Popconfirm placement="bottom" title={text} onConfirm={confirm}>
<Button>下边</Button>
</Popconfirm>
<Popconfirm placement="bottomRight" title={text} onConfirm={confirm}>
<Button>下右</Button>
</Popconfirm>
</div>
</div>, mountNode);
import { Popconfirm, Switch, message } from 'antd';
let App = React.createClass({
getInitialState() {
return {
visible: false,
condition: true,
};
},
changeCondition(value) {
this.setState({ condition: value });
},
confirm() {
this.setState({ visible: false });
message.success('进行下一步操作. next step.');
},
cancel() {
this.setState({ visible: false });
message.error('点击了取消');
},
handleVisibleChange(visible) {
if (!visible) {
this.setState({ visible });
return;
}
console.log(this.state.condition);
if (this.state.condition) {
this.confirm();
} else {
this.setState({ visible });
}
},
render() {
return <div>
<Popconfirm title="确定要删除这个任务吗?"
visible={this.state.visible} onVisibleChange={this.handleVisibleChange}
onConfirm={this.confirm} onCancel={this.cancel}>
<a href="#">删除某任务</a>
</Popconfirm>
<br />
<br />
点击是否直接执行:<Switch defaultChecked onChange={this.changeCondition} />
</div>;
}
});
ReactDOM.render(<App />, mountNode);