Guarded Switch

Guarded Switch is a copy-paste React component that stops helps prevent a kill switch flipped by accident before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/guarded-switch
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsHelps prevent a kill switch flipped by accident

Was this component page useful?

How do I install Guarded Switch?

pnpm dlx shadcn@latest add @bollard/guarded-switch

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

How do I use Guarded Switch in React?

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 input mistakes does Guarded Switch catch?

  • 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

What props does Guarded Switch accept?

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.

How is Guarded Switch accessible?

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

What are the limitations and server boundaries?

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 expensive mistakes does Guarded Switch stop?

Helps prevent a kill switch flipped by accident

Also known as

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

What dependencies does Guarded Switch require?

Guarded Switch facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameGuarded Switch
Registry identifier@bollard/guarded-switch
Install commandnpx shadcn@latest add @bollard/guarded-switch
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Guarded Switch

How does Guarded Switch protect destructive mutations?

Guarded Switch prevents a kill switch flipped by accident. Enforces deliberate friction against 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. Limitation: authorize guarded-switch mutations on the server.

How do I install guarded-switch with shadcn?

Run `npx shadcn@latest add @bollard/guarded-switch`. Sources added: registry/default/guarded-switch/guarded-switch.tsx. Package requirements: lucide-react.

What props customize Guarded Switch?

Guarded Switch accepts `label`, `onEffect`, `offEffect`, `value`, `defaultValue`. Configures toggle, switch, maintenance mode behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of guarded-switch?

A deliberate user can still flip it; it adds friction, not authorization. Does not confirm who flipped it or log the change Server requirement: Authorize and audit-log the setting change on the server.

How does Guarded Switch meet accessibility guidelines?

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. Minimizes errors: toggled maintenance mode by mistake, kill switch toggled.

Which components pair with Guarded Switch?