# Unsaved Changes

A settings form that keeps track of edits: a dot marks each changed field, Save counts them, pointing at Save lights them up with marks along the scroll edge for the ones out of view, and Cmd+S sends the dots flying into the button.

- Page and source: https://uibrik.com/components/unsaved-changes
- Install (Pro, needs a license key, see https://uibrik.com/docs/pro): `npx shadcn@latest add @uibrik-pro/unsaved-changes`
- Packages: none beyond React
- Import: `import { UnsavedChanges } from "@/components/uibrik/unsaved-changes/unsaved-changes"`

Where to use the Unsaved Changes React component:

- **Settings pages**: A dot on every edited field and a counted Save make it clear what will change. Pairs with [Settings Page](https://uibrik.com/components/settings-page).
- **Long forms**: Marks on the scroll edge point to edits that have scrolled out of view.
- **Guarding navigation**: Leaving with edits shakes the button and scrolls to the first one instead of losing it. Pairs with [Inline Confirm](https://uibrik.com/components/inline-confirm).

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| accent | `string` | `"#f59e0b"` | Colour of the change dots, the field highlight and the scroll marks. |
| guardLinks | `boolean` | `true` | Stops link clicks while there are edits: the button shakes and the first edit scrolls into view. A second click goes through. |
| beforeUnload | `boolean` | `true` | Asks the browser to confirm closing or reloading the tab while there are edits. |
| height | `number` | `560` | Height of the panel. The fields scroll inside it. |
| radius | `number` | `24` | Corner radius of the panel. |
| children | `ReactNode` |  | The fields. Wrap each in <UnsavedField name label hint?> around a native input, select or textarea with the same name. Edits are found by comparing values with the last save. |
| onSave | `(values, changed: string[]) => void \| Promise<void>` |  | Runs on Save or Cmd/Ctrl+S with every named value. A promise shows Saving until it settles; a rejection shakes the button and keeps the edits. |
| onDiscard | `() => void` |  | Runs after Discard resets the native fields. Reset any controlled fields here. |
| useUnsavedChanges() | `{ count, changed, save, discard, guard }` |  | Hook for children. Call guard() before a programmatic navigation: it returns true when it stopped it. |
| className | `string` |  | Classes for the panel. |
