Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Overlays

  • Dialog
  • Modal
  • AlertDialog
  • Drawer
  • Popover
  • Tooltip
  • HoverCard
  • Glimpse
  • HeroVideoDialog
  • ElementSelectionOverlay

Messages

  • Alert
  • InterceptCard
  • Callout
  • Banner
  • Toast
  • Notification
  • ServiceMessage
  • Result
  • GiftFeed
  • FloatingReactions
  • Popconfirm

Loading and Progress

  • Spin
  • Spinner
  • Progress

Guidance

  • Tour

Popconfirm

popconfirm

Confirms a nearby action in a compact anchored popup.

Usage

Basic usage

Wrap any trigger element and click the pop-up bubble to confirm. onConfirm triggers and automatically closes after point confirmation.

tsx
<Popconfirm title="Confirm submission?" onConfirm={() => {}}>
  <Button size="sm">Submit</Button>
</Popconfirm>

Dangerous operation

danger Make the confirmation button turn danger color and the default icon turn red, suitable for irreversible actions such as deletion.

tsx
<Popconfirm title="Are you sure you want to delete this record?" description="It cannot be recovered after deletion." danger onConfirm={() => {}}>
  <Button variant="outline" tone="danger" size="sm">Delete</Button>
</Popconfirm>

Asynchronous confirmation

onConfirm Confirm button enters loading when returning to Promise, and automatically closes after resolve.

tsx
<Popconfirm
  title="Confirm archiving?"
  description="Save asynchronously to server."
  okText="Archive"
  onConfirm={() => new Promise((r) => setTimeout(r, 1200))}
>
  <Button variant="outline" size="sm">Archive</Button>
</Popconfirm>

Pop-up direction + custom icon

side controls the floating layer orientation, and icon replaces the default warning triangle.

tsx
<Popconfirm
  title="Move to trash?"
  side="right"
  icon={<Trash2 className="size-5 shrink-0 text-danger" aria-hidden />}
  danger
  onConfirm={() => {}}
>
  <Button variant="ghost" size="sm" tone="danger">Recycling</Button>
</Popconfirm>

Custom button copy

okText / cancelText Override the default text of the confirm and cancel buttons.

tsx
<Popconfirm title="Log out?" okText="Log out" cancelText="Think again" onConfirm={() => {}}>
  <Button variant="outline" size="sm">Log out</Button>
</Popconfirm>

When to use

Use Popconfirm beside a table row or button when a dangerous or irreversible action such as Delete or Archive needs lightweight confirmation. It is more substantial than Toast but lighter than a full-screen Modal or AlertDialog.

Import

ts
import { Popconfirm } from "@hulianui/ui"

Props

NameTypeDefaultDescription
dangerbooleanfalseUses danger tone for the confirm button and default icon.
openboolean-Controlled open state, paired with onOpenChange.
defaultOpenbooleanfalseInitial open state when uncontrolled.
side"top"|"right"|"bottom"|"left""top"Preferred popup side.
align"start"|"center"|"end""center"Popup alignment.
sideOffsetnumber8Distance from the trigger.
disabledbooleanfalseSkips the confirmation: no popup opens, but a click still runs onConfirm. It means "no need to ask this time", not "this button is dead". Put disabled on the child element to make the button unclickable.
classNamestring-Class name forwarded to Popup.

Events

EventTypeDescription
onConfirm() => void | Promise<void>A Promise puts Confirm in loading state, closes on resolve, and stays open after reject.
onCancel() => voidCalled only by the explicit Cancel button, not outside click or Escape.
onOpenChange(open: boolean) => voidReports all open-state changes, including outside click, Escape, Confirm, and Cancel.

Slots

SlotTypeDescription
title*ReactNodeConfirmation question connected with aria-labelledby.
descriptionReactNodeSupporting copy connected with aria-describedby.
iconReactNodeundefined uses the warning triangle, null omits it, and a node replaces it.
okTextReactNodeConfirm copy. Defaults to built-in Chinese "\u786e\u8ba4", meaning “Confirm.”
cancelTextReactNodeCancel copy. Defaults to built-in Chinese "\u53d6\u6d88", meaning “Cancel.”
children*ReactElementSingle trigger element used as the positioning anchor. Its own onClick is dropped. The action always belongs in onConfirm.

Example

tsx
<Popconfirm title="Delete this record?" description="Deletion cannot be undone." danger onConfirm={() => {}}>
  <Button variant="outline" tone="danger" size="sm">Delete</Button>
</Popconfirm>

<Popconfirm title="Archive this record?" okText="Archive" onConfirm={async () => { await api.archive(id); }}>
  <Button variant="outline" size="sm">Archive</Button>
</Popconfirm>

// One button that only sometimes needs a confirmation - no need to keep two copies
<Popconfirm
  title="The body still has unfilled placeholders. Export anyway?"
  disabled={!hasPlaceholders}
  onConfirm={exportDocx}
>
  <Button variant="outline" loading={exporting}>Export Word</Button>
</Popconfirm>

The action belongs in onConfirm

An onClick on children is dropped, and development builds log a warning:

tsx
// Correct: the action lives in onConfirm
<Popconfirm title="Delete this record?" danger onConfirm={remove}>
  <Button tone="danger">Delete</Button>
</Popconfirm>

// Wrong: before 0.45.0 this ran the deletion first and only then asked about it
<Popconfirm title="Delete this record?" danger>
  <Button tone="danger" onClick={remove}>Delete</Button>
</Popconfirm>

This differs from Popover and Tooltip on purpose: opening those overlays should not swallow whatever the child already did, so merging is right for them. Popconfirm exists to stop the action, so replacing is the only self-consistent option.

A handler that only calls stopPropagation (common inside clickable table rows) goes as well, so move it to a wrapper outside Popconfirm:

tsx
<span onClick={(e) => e.stopPropagation()}>
  <Popconfirm title="Delete this record?" danger onConfirm={remove}>
    <Button tone="danger" size="sm">Delete</Button>
  </Popconfirm>
</span>

Usage guidelines

  • disabled does not disable the button, it skips the question: no popup, but the click still runs onConfirm. Put disabled on the child element to make the button unclickable.
  • When onConfirm returns a Promise, only resolve closes. Rejection clears loading and remains open; the caller owns error feedback.
  • onCancel runs only for the explicit button. Put cleanup that must run for outside click or Escape in onOpenChange.
  • children must be one ReactElement, not text or a Fragment, because it anchors the popup.
  • In controlled use, always pair open and onOpenChange or dismissal cannot update state.

Related

Alert · Banner · Toast · Notification · ServiceMessage · Result

Playground

<Popconfirm
  title="Are you sure you want to delete this record?"
  description="Cannot be recovered after deletion."
  danger
  side="top"
  onConfirm={async () => { await api.remove(id); }}
>
  <Button variant="outline" tone="danger" size="sm">Delete</Button>
</Popconfirm>
PreviousFloatingReactionsFeedbackNextSpin

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Example
    • The action belongs in onConfirm
    • Usage guidelines
    • Related
  • Playground