Unsaved Changes
Protect work in forms that save explicitly, warning only when something would actually be lost.
6 states4 edge casesDesktop + Mobile
01The problem
Not every form autosaves. Settings, configuration and multi-field records often need an explicit Save. Users edit, get distracted, click a sidebar link and lose ten minutes of work. Products that warn too eagerly — on every page, even when nothing changed — train users to click “Leave” without reading.
02When to use
Use when
- Forms with an explicit Save button
- Settings pages and configuration editors
- Modals and drawers containing editable forms
Avoid when
- The form autosaves — use the autosave pattern instead.
- Changes are trivial to redo (a single search field).
03Recommended UX
Statecraft recommendation
Track whether the form differs from its saved state, show that clearly with a sticky save bar, and only warn on navigation, close or tab exit when there are real unsaved differences — offering Save, Discard and Cancel.
04Desktop behaviour
On desktop, a sticky bar at the bottom or top of the form shows unsaved state, and an in-app dialog guards navigation.
Desktop rules
- Sticky bar appears only while dirty: “Unsaved changes · Discard · Save”.
- In-app navigation guard: dialog with Save and leave / Discard / Keep editing.
- Browser close/refresh: native beforeunload prompt only while dirty.
- Cmd/Ctrl+S saves.
05Mobile behaviour
On mobile, back gestures and app switching are the common ways to leave. Guard back navigation and persist drafts locally.
Mobile rules
3 mobile rules are included in Pro.
Statecraft Pro
Unlock the full pattern
Get the complete interaction flow, states, edge cases, mobile rules and implementation prompt.
- Interaction flow · 5 steps
- 3 mobile rules
- 6 states
- 4 edge cases with recommendations
- 4 microcopy comparisons
- Accessibility notes
- Developer notes
- Claude Code / Codex implementation prompt
- React + TypeScript reference code and tests
Edge cases covered in this pattern
- Changes reverted by hand
- Invalid fields when leaving
- Modal forms
- Save conflicts