Save Bar API
App Bridge isn't versioned with Polaris. App Bridge APIs and web components are identical in every App Home reference version.
App Bridge isn't versioned with Polaris. App Bridge APIs and web components are identical in every App Home reference version.
The Save Bar API indicates that a form on the current page has unsaved information. You can implement save bar behavior in one of two ways:
-
Automatic (form attribute): Add the
data-save-barattribute to aformelement. The save bar displays automatically when there are unsaved changes. Thesubmitevent fires when the merchant clicks Save, and theresetevent fires when the merchant clicks Discard. This is the simplest approach for standard form workflows. App Bridge ignores values that your code sets. To keep the save bar in sync after your code changes form values, refer to How the save bar tracks changes. -
Programmatic (web component): Add a
<ui-save-bar>element with a uniqueidto your page, then useshopify.saveBar.show(id),shopify.saveBar.hide(id), andshopify.saveBar.toggle(id)to control it. The<ui-save-bar>element can contain<button>children for Save (withvariant="primary") and Discard. This approach gives you full control over when the save bar appears and what happens when merchants interact with it.
Choose one approach for each form. Don't combine data-save-bar on a form with programmatic shopify.saveBar methods. Each approach manages save bar visibility independently and using both can cause unexpected behavior.
Choose one approach for each form. Don't combine data-save-bar on a form with programmatic shopify.saveBar methods. Each approach manages save bar visibility independently and using both can cause unexpected behavior.
Anchor to Use casesUse cases
- Standard forms: Use the
data-save-barattribute on aformelement to automatically detect and manage unsaved changes with save and discard actions. - Custom state management: Use the
<ui-save-bar>web component withshopify.saveBarmethods to control the save bar based on application state that isn't tied to a single form. - Data protection: Prevent accidental data loss by prompting users when leaving a page with unsaved changes using
shopify.saveBar.leaveConfirmation().
Anchor to MethodsMethods
The object provides methods to programmatically control save bar visibility.
- Anchor to hidehidehide(id: string) => Promise<void>(id: string) => Promise<void>
Hides the save bar. Call this after the merchant saves or discards their changes.
- Anchor to leaveConfirmationleave
Confirmationleave Confirmation () => Promise<void>() => Promise<void> Prompts the merchant to confirm before leaving the page when there are unsaved changes. The promise resolves when the merchant confirms or when no save bar is visible. Use this before programmatic navigation (for example, using
window.locationor custom routing) to prevent accidental data loss.- Anchor to showshowshow(id: string) => Promise<void>(id: string) => Promise<void>
Displays the save bar to indicate unsaved changes. Call this when you want to prompt the merchant to save.
- Anchor to toggletoggletoggle(id: string) => Promise<void>(id: string) => Promise<void>
Toggles save bar visibility between shown and hidden states.
html
Preview

Examples
Display a save bar
Description
Display a save bar. This example adds the `data-save-bar` attribute to a form element. When the form has unsaved changes, the save bar appears automatically.
html
<form data-save-bar onSubmit="console.log('submit', new FormData(event.target)); event.preventDefault();" > <label> Name: <input name="username" /> </label> </form>Handle discard events
Description
Handle discard events. This example subscribes to the [`reset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset_event) event to run custom logic when the merchant clicks the Discard button.
Event handler property
<form data-save-bar onReset="console.log('discarding')" > <label> Name: <input name="username" /> </label> </form>Event listener
<form data-save-bar> <label> Name: <input name="username" /> </label> </form> <script> const form = document.querySelector('form'); form.addEventListener('reset', (e) => { console.log('discarding'); }); </script>Handle save events
Description
Handle save events. This example subscribes to the [`submit`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit_event) event to run custom logic when the merchant clicks the Save button.
Event handler property
<form data-save-bar onSubmit="console.log('submitting');" > <label> Name: <input name="username" /> </label> </form>Event listener
<form data-save-bar> <label> Name: <input name="username" /> </label> </form> <script> const form = document.querySelector('form'); form.addEventListener('submit', (e) => { console.log('submitting'); }); </script>Show discard confirmation
Description
Show discard confirmation. This example adds the `data-discard-confirmation` attribute to show a confirmation modal when the merchant clicks the Discard button, preventing accidental data loss. For a `<ui-save-bar>` element, add the `discardConfirmation` attribute instead. Refer to [The `ui-save-bar` element](#the-ui-save-bar-element).
html
<form data-save-bar data-discard-confirmation onSubmit="console.log('submit', new FormData(event.target)); event.preventDefault();" > <label> Name: <input name="username" /> </label> </form>Control save bar programmatically
Description
Control the save bar programmatically. This example defines a `<ui-save-bar>` element with an `id`, then uses `shopify.saveBar.show(id)` and `shopify.saveBar.hide(id)` to manage visibility based on application state.
tsx
function SaveBarExample() { const saveBarId = 'settings-save-bar'; const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false); const handleFieldInput = () => { if (!hasUnsavedChanges) { setHasUnsavedChanges(true); shopify.saveBar.show(saveBarId); } }; const handleDiscard = () => { setHasUnsavedChanges(false); shopify.saveBar.hide(saveBarId); }; const handleSave = async () => { // Save to your backend setHasUnsavedChanges(false); shopify.saveBar.hide(saveBarId); }; return ( <s-page heading="Settings"> <ui-save-bar id={saveBarId}> <button variant="primary" onClick={handleSave}>Save</button> <button onClick={handleDiscard}>Discard</button> </ui-save-bar> <s-section heading="Configuration"> <s-text-field label="Store name" onInput={handleFieldInput} /> </s-section> </s-page> ); }Toggle save bar
Description
Toggle the save bar. This example defines a `<ui-save-bar>` element with an `id`, then uses `shopify.saveBar.toggle(id)` to switch between shown and hidden states.
tsx
function ToggleExample() { const saveBarId = 'toggle-save-bar'; const handleToggle = () => { shopify.saveBar.toggle(saveBarId); }; return ( <s-page heading="Settings"> <ui-save-bar id={saveBarId}> <button variant="primary">Save</button> <button>Discard</button> </ui-save-bar> <s-section heading="Controls"> <s-button onClick={handleToggle}> Toggle save bar </s-button> </s-section> </s-page> ); }Leave confirmation
Description
Guard programmatic navigation when unsaved changes exist. `shopify.saveBar.leaveConfirmation()` resolves when no save bar is visible or when the merchant confirms leaving without saving edits. If the merchant cancels, or when the Shopify admin shakes a visible save bar on the web, then the promise stays pending and doesn't reject or resolve with `false`.
tsx
function LeaveConfirmationExample() { const saveBarId = 'leave-confirm-save-bar'; const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false); const handleFieldInput = () => { if (!hasUnsavedChanges) { setHasUnsavedChanges(true); shopify.saveBar.show(saveBarId); } }; const handleCustomNavigation = async () => { // Call leaveConfirmation before programmatic navigation await shopify.saveBar.leaveConfirmation(); // Navigation proceeds after merchant confirms or if no unsaved changes window.location.href = '/other-page'; }; return ( <s-page heading="Settings"> <ui-save-bar id={saveBarId}> <button variant="primary">Save</button> <button>Discard</button> </ui-save-bar> <s-section heading="Configuration"> <s-text-field label="Store name" onInput={handleFieldInput} /> <s-button onClick={handleCustomNavigation}> Go to other page </s-button> </s-section> </s-page> ); }Controlled inputs
Description
Show the save bar when React state changes. This example uses `<ui-save-bar>` with `shopify.saveBar.show(id)` while the selected product differs from the saved value and `shopify.saveBar.hide(id)` when they match. Don't use an `<input type="hidden">` with `data-save-bar`. On a fresh page, changing a hidden input's value also updates its default value, and App Bridge misses the change.
tsx
const saveBarId = 'featured-product-save-bar'; function ReactControlledInputsExample() { const [selectedProduct, setSelectedProduct] = React.useState<{ id: string; title: string; } | null>(null); const [savedProduct, setSavedProduct] = React.useState<{ id: string; title: string; } | null>(null); const dirty = selectedProduct?.id !== savedProduct?.id; React.useEffect(() => { if (dirty) { shopify.saveBar.show(saveBarId); } else { shopify.saveBar.hide(saveBarId); } }, [dirty]); const openResourcePicker = async () => { const selected = await shopify.resourcePicker({type: 'product'}); if (selected?.length) { const product = selected[0]; setSelectedProduct({ id: product.id, title: product.title, }); } }; const handleSave = async () => { const response = await fetch('/api/save', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({productId: selectedProduct?.id ?? null}), }); if (response.ok) { setSavedProduct(selectedProduct); } }; const handleDiscard = () => { setSelectedProduct(savedProduct); }; return ( <s-page heading="Settings"> <ui-save-bar id={saveBarId}> <button variant="primary" onClick={handleSave}> Save </button> <button onClick={handleDiscard}>Discard</button> </ui-save-bar> <s-section heading="Featured product"> {selectedProduct ? ( <s-clickable-chip removable onRemove={() => setSelectedProduct(null)}> {selectedProduct.title} </s-clickable-chip> ) : ( <s-button onClick={openResourcePicker}>Select product</s-button> )} </s-section> </s-page> ); }
Anchor to The ui-save-bar elementThe ui-save-bar element
ui-save-bar elementA <ui-save-bar> element takes these attributes and children:
id: The identifier that you pass toshopify.saveBar.show(),shopify.saveBar.hide(), andshopify.saveBar.toggle().discardConfirmation: A Boolean attribute. When the element has it, a confirmation dialog shows when the merchant clicks Discard. For example,<ui-save-bar id="my-save-bar" discardConfirmation>. Thedata-discard-confirmationattribute works only on a<form>with thedata-save-barattribute, and has no effect on a<ui-save-bar>element.<button variant="primary">: Receives a click when the merchant clicks Save. A<button>without a variant receives a click when the merchant clicks Discard. Add thedisabledorloadingattribute to a button to disable it or show it as loading in the save bar.
The element has these methods, properties, and events:
show(): Shows the save bar. Returns a promise.hide(): Hides the save bar. Returns a promise.toggle(): Shows the save bar when it's hidden, and hides it when it's showing. Returns a promise.showing: A read-only property that'struewhile the save bar shows.discardConfirmation: A property that gets or sets thediscardConfirmationattribute.showandhideevents: Fire when the save bar shows and when it hides.
shopify.saveBar.show(id), shopify.saveBar.hide(id), and shopify.saveBar.toggle(id) call the same method on the <ui-save-bar> element with that id. If no element on the page has that id, then the promise rejects.
While the save bar shows, the Shopify admin keeps the merchant on the current page: links in the admin don't open, and the save bar shakes. If your app changes its own route, then your app shows the new page, but the admin's address bar keeps the previous page, and a reload opens that previous page. Your app changes its route when it calls history.pushState(), when it calls a router function such as navigate(), and when its router follows a redirect after a form action. To learn how the address bar follows your app, refer to Address bar sync.
Before your app navigates away from a page with unsaved changes, decide what happens to those changes:
- The navigation ends the edit: For example, the merchant deletes a resource, and your app redirects to a list. Hide the save bar before you start the navigation. For a
<ui-save-bar>element, wait forshopify.saveBar.hide(id). For a form with thedata-save-barattribute, call the form'sreset()method, which also runs yourresetevent handlers. - The merchant decides: Wait for
shopify.saveBar.leaveConfirmation()before you navigate. The promise resolves when no save bar is visible or when the merchant confirms leaving without saving edits. Confirming runs your Discard handler and hides the save bar. If the merchant cancels, or when the Shopify admin shakes a visible save bar on the web, then the promise stays pending and doesn't reject or resolve withfalse. Code afterawaitdoesn't run. Keepcatchblocks for unexpected errors, not cancellation.
Don't rely on removing the <ui-save-bar> element or the form from the page to hide the save bar. The admin receives your app's route change while the save bar still shows, so the address bar stays on the previous page.
The following example waits for shopify.saveBar.leaveConfirmation() before calling your app router's navigate() function. Navigation runs when no save bar is visible or after the merchant confirms leaving. If the merchant cancels or a visible save bar blocks navigation, then the promise stays pending and navigate() doesn't run:
React Router
The following example hides the save bar before it submits a delete with React Router. The route's action deletes the QR code and redirects to the app's index page: