Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Confirm Action Dialog Block for React

A newsletter editor with its publish confirmation shown open: an alert dialog that lists what happens to the issue, a box that remembers the answer, and a foot that gives the question back.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Ask once, plainly, before something goes out, with this confirmation for React with Base UI. It opens from the editor of Lettercrate, a newsletter tool: the header holds an outline Publish Button, and the issue itself is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The Alert Dialog says what publishing does in a short list: how many subscribers on how many lists get it and when, that the archive page lists it, and that the issue locks. A Checkbox says "Don't ask me again for publishing", with a line under it that says what ticking does; Cancel has focus when it opens, and Publish, the only Shine Button, goes out. Publishing flips the drawn issue to Published, locks it, and turns the header's button into Undo publish. If the box was ticked, the next press of Publish acts at once, and Ask again in the foot brings the question back. For preview the alert is drawn open in place when the page loads; the header button opens the real Alert Dialog, with the same list and the same box. For publishing, sending, merging and anything that is easy to repeat but not to take back.

FAQ

Why is the alert already open, and what do I keep?

So you can see it without a click. On load the alert is a copy drawn in place over the editor: a native dialog element with the alertdialog role that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Publish button in the header opens the real Alert Dialog, modal, with its focus trap, Escape and focus on Cancel, and the copy stays closed until a reload. Both show the same ConfirmFields component and share the block's state, so a box ticked in the copy is ticked in the real one. In your app keep the Alert Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.

How does it remember not to ask again?

skip is block state. Tick the box and confirm, and the next press of Publish publishes at once, with a polite message saying it did so without asking. The foot's Ask again button turns the question back on, and pressing it while the question is already on says so instead of doing nothing silently. In your app store the choice per person, in your database or at least in localStorage, and show a way back to it in the account settings, since a hidden choice can't be undone.

What does Publish do here, and how do I wire it up?

Here it flips the drawn issue to Published, locks it, says "Published in this demo. Nothing sent." in the foot's polite status line, and turns the header's button into Undo publish, which puts the draft back. Nothing is published or sent. In your app call your server in confirm, keep the alert open with its busy state until it answers, and flip the issue on success; on failure keep the alert open and say what failed beside Publish. Offer Undo only for as long as your server really holds the send.

Where do the counts and the date come from?

LISTS holds each list and its subscribers, and the total is the sum of them, so the count in the first line can't disagree with the lists under it. The send day is SENDS_ON, an ISO date written in UTC, so it reads the same on the server and in every visitor's time zone. Swap them for the lists and the schedule your server returns.

Where does focus go, and how does it close?

The real alert is named by its title and described by its sentence, and it opens with focus on Cancel, never on Publish, so a stray Enter backs out. Escape and Cancel close it and return focus to the Publish button; clicking outside does not close it, since an alert has to be answered. Cancel is the focus target through initialFocus. After a confirmed publish the button that opened the alert is gone, so about 300 ms later focus moves to Undo publish, the button that took its place. The copy shown on load moves no focus; Escape inside it, Cancel and Publish close it the same way.

Why is Publish a Shine Button, and how does it look on a phone?

Publishing moves the issue forward and can be undone, so its confirm is the block's one primary and the Shine Button; a confirm that deletes uses the destructive Button instead, as the confirm delete dialog does. On a phone the copy shown on load docks to the foot of the frame as a bottom sheet with Cancel and Publish side by side, and the list scrolls above them if the frame is short. The real alert keeps the Alert Dialog's own layout: a centred card as wide as the screen allows.

  • Pro

    Confirm Delete Dialog

    Destructive confirms

    A planner's project list with its delete confirmation shown open: an alert dialog that lists what goes with the project, asks for its name to be typed exactly, and keeps Delete off until it matches.

  • Pro

    Two Actions Dialog

    Confirm and consent

    A mail client with its sent confirmation shown open: a dialog with a View message button and an Undo whose label counts down from 10 while a fill drains, with Return to drafts staying on the page.

  • Pro

    Warning Dialog

    Destructive confirms

    A hosted database's Migrations page with its caution shown open: an alert dialog with a drawn freeze track and a checkbox that must be ticked before the destructive Run anyway turns on.

  • Pro

    Upgrade Proration Billing

    Upgrade and downgrade

    Changing plan inside app settings with the bill worked out first: pick a higher plan and the credit for unused days, the new plan's cost for those days, what's due today and the next invoice roll live, then an alert dialog confirms the charge.

  • Pro

    Unsaved Changes Dialog

    Confirm and consent

    An essay editor with its leave prompt shown open: an alert dialog that lists what changed since the last save and offers Save and leave, Discard changes and Keep editing.

  • Pro

    Cookie Settings Dialog

    Confirm and consent

    A newspaper's cookie preference centre shown open over its front page: four categories with switches and counts, Essential locked on, and for the chosen one a sentence and a table of its actual cookies, then Reject non-essential, Accept all and Save choices.