javascript - Ant Design Popconfirm - Changing the preselected button to Cancel - Stack Overflow

The Popconfirm-modal in Ant Design has the Confirm ("Yes"-)-Button preselected when the modal

The Popconfirm-modal in Ant Design has the Confirm ("Yes"-)-Button preselected when the modal-window opens.

Source-code for the modal:

import { Popconfirm, message } from 'antd';

function confirm(e) {
  console.log(e);
  message.success('Click on Yes');
}

function cancel(e) {
  console.log(e);
  message.error('Click on No');
}

ReactDOM.render(
  <Popconfirm title="Are you sure delete this task?" onConfirm={confirm} onCancel={cancel} okText="Yes" cancelText="No">
    <a href="#">Delete</a>
  </Popconfirm>
, mountNode);

Documentation and live-demo here: Ant Design Documentation

Is there a way to change the described default-behaviour?

Precisely: Is there a way to define the Cancel (respectively "No"-)-Button as preselected when the Modal appears?

The Popconfirm-modal in Ant Design has the Confirm ("Yes"-)-Button preselected when the modal-window opens.

Source-code for the modal:

import { Popconfirm, message } from 'antd';

function confirm(e) {
  console.log(e);
  message.success('Click on Yes');
}

function cancel(e) {
  console.log(e);
  message.error('Click on No');
}

ReactDOM.render(
  <Popconfirm title="Are you sure delete this task?" onConfirm={confirm} onCancel={cancel} okText="Yes" cancelText="No">
    <a href="#">Delete</a>
  </Popconfirm>
, mountNode);

Documentation and live-demo here: Ant Design Documentation

Is there a way to change the described default-behaviour?

Precisely: Is there a way to define the Cancel (respectively "No"-)-Button as preselected when the Modal appears?

Share Improve this question asked Feb 20, 2018 at 12:59 cluster1cluster1 5,8587 gold badges38 silver badges59 bronze badges 2
  • What do you mean with "preselected" ? it's preselected to none. do you want to invert the button with primary (blue) color to the "cancel" button? – Yichz Commented Feb 21, 2018 at 23:25
  • @Kossel Yes. Exactly. I like to have the cancel-button (as the more harmless action) to be blue. And the harmful action NOT highlighted when the window appears. – cluster1 Commented Feb 22, 2018 at 10:37
Add a ment  | 

1 Answer 1

Reset to default 3

You can only get half-way I am afraid.

If you provide an okType="default" property, the "Yes" button will no longer have type="primary", and thus look just like the "No" button.

However there is no support for a corresponding cancelType property, which means you are not able to make the "No" button blue.

This does feel like a slightly limping API, so you might have success filing a PR implementing cancelType. Should be a very simple 3-line patch against https://github./ant-design/ant-design/blob/master/ponents/popconfirm/index.tsx

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745361723a4624391.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信