Skip to main content

Popconfirm

A simple confirmation dialog triggered by a click on an element.

When To Use

  • To confirm a user action before executing it
  • As a lightweight alternative to Modal for simple confirmations
  • When the action is destructive or cannot be easily undone

Basic Usage

import { TxPopconfirm, TxButton } from "tx-design-ui";

function Example() {
const handleConfirm = () => {
console.log("Confirmed!");
};

return (
<TxPopconfirm title="Are you sure to delete this item?" onConfirm={handleConfirm}>
<TxButton type="danger">Delete</TxButton>
</TxPopconfirm>
);
}

Placement

Set the position of the popconfirm relative to the target element.

<TxPopconfirm title="Delete this item?" placement="top">
<TxButton type="danger">Top</TxButton>
</TxPopconfirm>

<TxPopconfirm title="Delete this item?" placement="bottom">
<TxButton type="danger">Bottom</TxButton>
</TxPopconfirm>

<TxPopconfirm title="Delete this item?" placement="left">
<TxButton type="danger">Left</TxButton>
</TxPopconfirm>

<TxPopconfirm title="Delete this item?" placement="right">
<TxButton type="danger">Right</TxButton>
</TxPopconfirm>

Custom Text

Customize the button text and type.

<TxPopconfirm
title="Do you want to archive this?"
okText="Archive"
cancelText="Cancel"
onConfirm={() => console.log("Archived")}
>
<TxButton>Archive</TxButton>
</TxPopconfirm>

<TxPopconfirm
title="Confirm submission?"
okText="Submit"
cancelText="Back"
okType="success"
onConfirm={() => console.log("Submitted")}
>
<TxButton type="primary">Submit</TxButton>
</TxPopconfirm>

API

PropertyTypeDefaultDescription
childrenReactNode-Target element (required)
titlestring | ReactNode'Are you sure?'Confirmation message
placement'top' | 'bottom' | 'left' | 'right''bottom'Position of the popconfirm
onConfirmfunction(e)-Callback when OK is clicked
onCancelfunction(e)-Callback when Cancel is clicked
okTextstring'Yes'Text of the OK button
cancelTextstring'No'Text of the Cancel button
okTypestring'primary'Button type of the OK button

Notes

  • Use Popconfirm for simple yes/no confirmations
  • For complex confirmations with forms, use Modal instead
  • The popconfirm closes automatically after clicking OK or Cancel
  • Consider using warning icon color for destructive actions