Guarded Switch

Puts a lift-up cover over a critical switch like maintenance mode or a kill switch, so a stray click can't flip it.

StopsHelps prevent a kill switch flipped by accident

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/guarded-switch.json

The files land in your project. They're yours to edit.

Usage

guarded-switch-usage.tsx
import { GuardedSwitch } from "@/components/ui/guarded-switch"

<GuardedSwitch
  label="Maintenance mode"
  onEffect="Site goes offline for all 12,400 users"
  offEffect="Site comes back online for all 12,400 users"
/>

What it catches

  • Stray click or tap on a critical toggle
  • Flipping without knowing the effect: the on/off consequence is shown while the guard is up
  • Guard left open: it closes again on its own
  • A rejected change keeps the old state

Props

GuardedSwitch props
PropTypeDefault
label* (required)

The setting's name, e.g. "Maintenance mode". Also the switch's accessible name.

string—
onEffect* (required)

What turning it on does, e.g. "Site goes offline for all 12,400 users".

string—
offEffect* (required)

What turning it off does, e.g. "Site comes back for all 12,400 users".

string—
value

Controlled state.

boolean—
defaultValue

Initial state when uncontrolled.

booleanfalse
onValueChange

Called with the new state. Return a promise to show a pending state; a rejection keeps the old state.

(value: boolean) => void | Promise<void>—
tone

`red` for irreversible or high-blast-radius settings, `black` for reversible ones.

keyof typeof tones"red"
openFor

How long the lifted cover stays up, in milliseconds. Pauses while the pointer is over the switch.

number4000
disabled

Disables the cover and the switch.

boolean—
liftLabel

Accessible name of the cover. `{label}` is filled in.

string"Lift cover to change {label}"
armedText

Shown while the cover is up. `{state}` and `{effect}` are filled in.

string"Flipping {state}: {effect}."
changedText

Read back after a flip. `{label}`, `{state}` and `{effect}` are filled in.

string"{label} is {state}. {effect}."
onText

State text when on.

string"on"
offText

State text when off.

string"off"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • The switch has role=switch, aria-checked, a label and a description; it is out of the tab order until the cover is lifted
  • Cover is a button with aria-expanded and an aria-label; Escape closes it and focus moves sensibly between cover and switch
  • Effect line is a polite live region
  • Pending state uses aria-busy; icons are aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Authorize and audit-log the setting change on the server.

  • A deliberate user can still flip it; it adds friction, not authorization
  • Does not confirm who flipped it or log the change

What it stops

Helps prevent a kill switch flipped by accident

Also known as

toggle · switch · maintenance mode · kill switch · feature toggle · settings toggle · guarded toggle

Dependencies

Pairs well with