Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Warning Dialog Block for React

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.

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

Make a risky run a considered one, with this caution dialog for React with Base UI. It opens from the Migrations page of Warrenbase, a hosted database that is in a maintenance freeze until 06:00: the header holds an outline Run migration Button, and the console is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The Alert Dialog puts a caution tile at the start and the question beside it, then a drawn freeze track: a strip of 24 hours with 22:00 to 06:00 shaded and footed with a solid bar (so shape, not colour, carries it), a marker at the typed 23:10, and the line "Freeze ends in 6 h 50 min", worked out from those two times across midnight. A Checkbox says what the person understands, with a line under it that says Run anyway turns on once it is ticked, and only then does Run anyway, the catalog Button in its destructive variant, turn on. Cancel has focus when it opens. Running it marks the drawn query block "Ran during the freeze in this demo" with a Needs review Badge. For preview the alert is drawn open in place when the page loads; the header button opens the real Alert Dialog, with the same track and the same box. For migrations, deploys, bulk edits and anything that is allowed but not advised.

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 console: 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 Run migration 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 CautionFields 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. On a phone the copy docks to the foot of the page as a bottom sheet, Cancel and Run anyway side by side and pinned while the text, the track and the box scroll above them; the real alert keeps the Alert Dialog's own centred layout.

How is the freeze track worked out?

Three typed times drive it: the freeze starts at 22:00, ends at 06:00 and the demo's clock reads 23:10. frozenAt shades an hour when it falls inside the freeze, which wraps midnight, waitMinutes takes the minutes to the end the same way (410, so 6 h 50 min), and the marker sits at 23:10's share of the day. The strip is one image with a sentence as its name, and the same facts are in the text under it. In your app pass the real maintenance window and read the clock from the server; the demo never reads the visitor's.

Why does Run anyway wait for a checkbox?

A freeze exists so that nothing changes while it holds, so the dialog asks the person to say they know what they are doing before the red button works. The checkbox sits in a label with the sentence, so the whole line is the target, and Run anyway is disabled until it is ticked. Cancel is first in the order and has focus when the alert opens, a click outside does not close it, and Escape and Cancel both leave the migration unrun. Use a typed confirmation instead when the action can't be undone at all.

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

Nothing runs. It marks the drawn query block "Ran during the freeze in this demo", adds a Needs review badge and says so in a polite status message. In your app start the migration in run, keep the alert open with a busy state until the server answers, mark the result only on success, and show a failure inside the alert with a retry. Record who ran it during the freeze, because the badge only helps if somebody reviews it.

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 Run anyway, so a stray Enter backs out. Escape and Cancel close it and return focus to Run migration. Cancel is the focus target through initialFocus. The copy shown on load moves no focus; Escape inside it, Cancel and Run anyway close it the same way.

Why isn't the action a Shine Button?

A confirm that does something risky uses the catalog Button in its destructive variant, and the block has no Shine Button: the Shine Button is the one primary for actions that move something forward, and this one is a deliberate exception. The destructive colour is on that button only. The caution tile, the track and the lines stay in the theme's neutral tones, so the warning doesn't depend on seeing red.

  • 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

    A hosting dashboard with an alert dialog shown open that asks for the password again before a project is deleted: a lock tile, one field, a Caps Lock note, a count of tries and a destructive confirm.

  • 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

    Downgrade Confirmation Billing

    Upgrade and downgrade

    A downgrade that shows what it costs first: the limits that shrink, the folders now over the smaller plan's storage with a checkbox to archive each and a live meter, the day it takes effect, and an alert dialog that asks for a typed word.

  • Pro

    Confirm Action Dialog

    Confirm and consent

    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.

  • Pro

    Session Timeout Dialog

    Status and errors

    A bank's accounts page with an alert dialog shown open that warns before an idle session ends: a one-minute clock with a draining bar, Stay signed in and Sign out now, and a signed-out view at zero.