On 1.0.0?
Upgrade today.
@oblique-code/form-guard warns people before they lose unsaved form changes: on refresh, tab close, the back button and link clicks. It has zero dependencies, weighs about 5 kB gzipped and comes with React and Vue adapters.
The first fix below affects every page that uses the library, so if you are on 1.0.0, please upgrade. It is a drop-in replacement.
npm i @oblique-code/ form-guard@1.0.1Fewer false alarms.
Better behavior.
- No more false “Leave site?” warnings. The browser’s leave dialog now only appears when there are unsaved changes.
- Client-side routing works again. After someone confirms they want to leave, the link click is replayed, so Next.js, React Router and similar routers navigate without a full page reload.
- Ctrl/Cmd-click, middle-click, downloads and in-page
#anchorlinks are never intercepted. - One prompt, not two. Choosing “Leave” in the modal no longer triggers the browser’s own dialog as well, and several guards on one page share a single prompt.
- Failed validation no longer counts as a save. A form submitted with an empty required field stays protected.
addForm()keeps unsaved changes,removeForm()updates the dirty state, and a native form reset is detected.
A modal that works
for everyone.
The confirmation modal now actually receives keyboard focus. Before, focus stayed on the page behind it, so the Tab trap and Escape key didn’t work as intended. The “Leave” button’s color contrast now meets WCAG AA in light and dark mode, checked with an automated axe-core audit.
Easier to install,
in any setup.
- The stylesheet ships as
dist/styles.css: import@oblique-code/form-guard/styles.cssor load it from a CDN. The old/src/styles.csspath still works. - TypeScript types now work for CommonJS
require()as well asimport, with everymoduleResolutionsetting. - Bundlers no longer drop the CSS import, and sites with a strict Content-Security-Policy get a styled modal automatically.
Three small
behavior changes.
- A guard you have called
disable()on never prompts. reset()only firescleanif the form was actually dirty.- Submitting an invalid form no longer resets the guard.
Tested in
real browsers.
This release adds a full test suite: unit tests, plus end-to-end tests in Chromium, Firefox and WebKit covering native dialogs, keyboard use, client-side routing, the back button, every form field type and an accessibility audit. Most of the fixes above were found by those tests.
Read the full changelog (opens in a new tab)Coming in
version 1.1.
Version 1.1 focuses on framework ergonomics: an isDirty value that re-renders in React, ready-made helpers for Next.js, React Router and Vue Router, and getChanges() to see exactly which fields changed.