Unsaved Changes Bar

Unsaved Changes Bar is a copy-paste React component that stops left page with unsaved edits 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/unsaved-changes-bar
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

StopsLeft page with unsaved edits

Was this component page useful?

How do I install Unsaved Changes Bar?

pnpm dlx shadcn@latest add @bollard/unsaved-changes-bar

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

How do I use Unsaved Changes Bar in React?

unsaved-changes-bar-usage.tsx
import { UnsavedChangesBar, useUnsavedChanges } from "@/components/ui/unsaved-changes-bar"

<UnsavedChangesBar
  fields={dirty}
  labels={labels}
  onSave={() => new Promise<void>((resolve) => setTimeout(() => { setSaved(draft); resolve() }, 700))}
  onDiscard={() => setDraft(saved)}
  onRevertField={(key) => setDraft((d) => ({ ...d, [key]: saved[key as keyof Profile] }))}
  className="bottom-0"
/>

What input mistakes does Unsaved Changes Bar catch?

  • Each changed field, by name
  • Fields edited back to their saved value (clean again, deep compare)
  • Closing the tab with unsaved edits (beforeunload)
  • Discard, which needs a second confirm
  • Save failures, shown as an error

What props does Unsaved Changes Bar accept?

UnsavedChangesBar props
PropTypeDefault
fields* (required)

Dirty field keys, usually from `useUnsavedChanges`. The bar hides when empty.

string[]—
labels

Human labels per key, e.g. `{ email: "Email" }`. Falls back to the key itself.

Record<string, string>{}
onSave* (required)

Persist the changes. Return a promise to show a saving state; throw to keep the bar.

() => void | Promise<void>—
onDiscard* (required)

Throw away every change. Only called after the inline confirm.

() => void—
onRevertField

Revert one field. When given, each field chip becomes a one-tap undo.

(field: string) => void—
guardUnload

Warn before closing or reloading the tab while there are changes.

booleantrue
summary

Headline. Defaults to "3 unsaved changes".

string—
confirmDiscardLabel

Question shown with the discard confirm. Defaults to "Discard all 3?".

string—
saveLabel

Save button text.

string"Save"
savingLabel

Save button text while saving.

string"Saving…"
discardLabel

Discard button text.

string"Discard"
keepLabel

Text of the button that cancels a discard.

string"Keep editing"
errorLabel

Shown when `onSave` throws something that isn't an `Error`.

string"Couldn't save. Your changes are still here."
regionLabel

Accessible name of the bar.

string"Unsaved changes"
changedFieldsLabel

Accessible name of the changed-fields list.

string"Changed fields"
revertLabel

Accessible label and tooltip of a field's revert button.

(field: string) => string(field) => `Revert ${field}`
confirmGroupLabel

Accessible name of the discard confirmation group.

string"Confirm discard"

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

How is Unsaved Changes Bar accessible?

  • Region with an aria-label; changed fields list has an aria-label
  • Ctrl/⌘+S saves (aria-keyshortcuts); revert buttons have aria-labels
  • Discard confirm is a labelled group focused on Keep; Escape cancels
  • Errors use role=alert; status in a polite live region

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

What are the limitations and server boundaries?

  • In-app navigation must be guarded by your router; only tab close is covered
  • Browsers show their own generic leave-page text

What expensive mistakes does Unsaved Changes Bar stop?

Left page with unsaved edits

Also known as

unsaved changes · dirty form · beforeunload · save bar · ctrl+s · settings form · react hook form · discard changes

What dependencies does Unsaved Changes Bar require?

Unsaved Changes Bar facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameUnsaved Changes Bar
Registry identifier@bollard/unsaved-changes-bar
Install commandnpx shadcn@latest add @bollard/unsaved-changes-bar
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 Unsaved Changes Bar

What form validation mistake does Unsaved Changes Bar catch?

Unsaved Changes Bar prevents left page with unsaved edits. Names every unsaved field, warns before the tab closes, saves on Ctrl/⌘+S and asks twice before discarding. Catches: Each changed field, by name, Fields edited back to their saved value (clean again, deep compare), Closing the tab with unsaved edits (beforeunload), Discard, which needs a second confirm, Save failures, shown as an error. Limitation: validate unsaved-changes-bar schemas on backend.

How do I install unsaved-changes-bar with shadcn?

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

What props customize Unsaved Changes Bar?

Unsaved Changes Bar accepts `fields`, `labels`, `onSave`, `onDiscard`, `onRevertField`. Configures unsaved changes, dirty form, beforeunload behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of unsaved-changes-bar?

In-app navigation must be guarded by your router; only tab close is covered. Browsers show their own generic leave-page text Server requirement: backend verification for unsaved-changes-bar.

How does Unsaved Changes Bar meet accessibility guidelines?

Region with an aria-label; changed fields list has an aria-label. Ctrl/⌘+S saves (aria-keyshortcuts); revert buttons have aria-labels. Discard confirm is a labelled group focused on Keep; Escape cancels. Errors use role=alert; status in a polite live region. Minimizes errors: lost changes on navigate, unsaved changes warning.

Which components pair with Unsaved Changes Bar?