Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Deactivate 2FA Dialog Block for React

A security page with its turn-off confirmation shown open: an alert dialog that lists what goes with two-step verification, asks for the password and a ticked acknowledgement, and keeps its destructive action quiet until both are done.

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 weakening an account a deliberate step, with this two-step turn-off for React with Base UI. It opens from the Sign-in security page of Pebblemail, a private email service: the header holds an outline Turn off two-step Button, and the page itself is drawn under a soft scrim inside a hairline frame with a plus mark on each corner, four settings in hairline cells with the Two-step one switched on. The Alert Dialog says what goes with the second step in a Data List: the authenticator app, the backup codes and the trusted browsers. A Password Input asks for the account password, a Checkbox says sign-in will rely on the password alone, and Turn off verification, the catalog Button in its destructive variant, stays quiet until both are done; pressed too early it names what is missing and goes there. Cancel has focus when it opens. Confirming flips the drawn cell from On to Off and turns the header's button into Turn on two-step. 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 fields. For two-step verification, passkeys, recovery methods and any switch that lowers an account's guard.

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 page: 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 Turn off two-step 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 DeactivateFields component and share the block's state, so a password typed in the copy is there 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 do the password and the box gate the button?

problemOf says what is missing: a password of fewer than MIN_PASSWORD characters, then the unticked box. The action is aria-disabled while anything is missing, not disabled, so it keeps its place in the tab order and a press answers: the reason appears in one reserved line above the buttons, which never moves them, and focus goes to the password or the box. Editing either clears the line. The destructive colour is on that button only; the rest of the dialog stays in the theme's neutral tones.

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

Here any password of eight or more characters passes, nothing is checked against an account and nothing is turned off. The drawn Two-step cell flips to Off, the trusted browsers cell dims with it, the header's button becomes Turn on two-step, and a polite status message says so. In your app verify the password on your server in confirm, remove the authenticator, the backup codes and the trusted browsers there, keep the alert open with its busy state until it answers, and show a wrong password in the password's own message. Send the account owner an email when the step is turned off.

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 the destructive action, so a stray Enter backs out. Escape and Cancel close it and return focus to the Turn off two-step button; clicking outside does not close it, since an alert has to be answered. Cancel is the focus target through initialFocus. After a confirmed turn-off the button that opened the alert is gone, so about 300 ms later focus moves to Turn on two-step, the button that took its place. The copy shown on load moves no focus; Escape inside it and Cancel close it the same way.

How does the password field behave?

It is the catalog Password Input with the current-password autofill hint, an eye button that shows or hides the characters and is a tab stop, and a hint that says what this demo accepts. The same id is on the input on every base, so its label and message are tied to it. The browser's password manager can fill it, so keep the hint and the label as they are.

How does it look on a phone?

The copy shown on load docks to the foot of the frame as a bottom sheet, its actions pinned at the bottom with Cancel beside Turn off verification, and the list and fields scroll above them. The real alert keeps the Alert Dialog's own layout: a centred card as wide as the screen allows, scrolling inside itself if the screen is short.

  • Pro

    An account's two-factor methods as rows with their role, history and a Test that opens a code field in place, Make primary, a guarded Remove, and a Set up that opens a QR code, a key name or a number.

  • 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

    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

    Two-Step Setup Dialog

    Account and security

    A cloud editor's security page with a three-step dialog shown open: a QR code and its key, eight backup codes to copy or download, and a six-digit check, ending in a note that two-step sign-in is on.

  • Pro

    Security Review Account

    Sessions and devices

    A security review in three sections, devices, recent sign-ins and sign-in methods, where each item is answered with Yes, this is mine or Remove, with a progress bar and a Finish button that waits for every answer.

  • 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.