Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to flip the position of the OK and Cancel buttons inside an Antd modal using okButtonProps and cancelButtonProps for button position

I'm using Antd's Modal component for a project and I'm attempting to customize it.

I need to flip the position of the ok and cancel buttons so that the ok button is on the left and the cancel is on the right.

I'm also attempting to change the icon color to red.

I looked into the PR that someone just put in for the Antd project to add this required functionality, but I can't anything that actually describes what prop I need to use in order to change the positioning.

I have a CodeSandbox below with my progress thus far

Edit nifty-khorana-frw23

import React from "react";
import ReactDOM from "react-dom";
import { Modal, Button } from "antd";
import "antd/dist/antd.css";

import "./styles.css";

function showConfirm() {
  Modal.confirm({
    title: "Do you Want to delete these items?",
    content: "Some descriptions",
    iconType: "close-circle",
    okButtonProps: {},
    cancelButtonProps: {},
    onOk() {
      console.log("OK");
    },
    onCancel() {
      console.log("Cancel");
    }
  });
}

function App() {
  return (
    <div className="App">
      <h1>Hello Modal</h1>
      <Button onClick={showConfirm}>Click For Modal</Button>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

like image 783
Josh Avatar asked Aug 06 '19 15:08

Josh


People also ask

How do I remove the OK and Cancel button on Modal ANTD?

According to the updated document (Aug 31, 2021), we only need to use footer={null} and don't have to use footer={null, null} anymore. BTW, if you want to do Login and close the Modal by clicking one button, you need to invoke the handler function (handleOk) and set the visible option to false inside of it.

How to close Modal in antd?

Modal.destroyAll() will destroy all confirmation modal dialogs. Usually, you can use it in router change event to destroy confirm modal dialog automatically.

What prevents ANTD Modal from closing when clicking outside?

According to Antd's documentation, you have two solutions: If you use the <Modal> in your component, you'd to set maskClosable={false} . This prevents you from viewing the modal when you press outside the modal area.


1 Answers

Modal.method() is pretty limited, so I would build custom modal using footer property.

Anyway, you can just flip the buttons or edit the CSS class like @Rikin mentioned:

function showConfirm() {
  Modal.confirm({
    title: 'Do you Want to delete these items?',
    content: 'Some descriptions',
    iconType: 'close-circle',
    okText: 'Cancel',
    cancelText: 'OK',
    okButtonProps: {
      type: 'default'
    },
    cancelButtonProps: {
      type: 'primary'
    },
    onOk() {
      console.log('Cancel');
    },
    onCancel() {
      console.log('OK');
    }
  });
}

Edit Q-57379945-FlipModalButtons

like image 145
Dennis Vash Avatar answered Sep 19 '22 21:09

Dennis Vash