Skip to content

Save bar

The foot of a settings form, with the last save's result and the Save button.

<form method="post" action="#" aria-label="Notification settings">
  <div class="cap-save-bar">
    <p role="status" class="cap-save-bar-status"></p>
    <button type="submit" class="cap-btn" data-variant="primary">Save changes</button>
  </div>
</form>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/save-bar.css";

Usage

<div class="cap-save-bar">
  <p role="status" class="cap-save-bar-status"><span class="cap-status" data-tone="ok">...Saved</span></p>
  <button type="submit" class="cap-btn" data-variant="primary">Save changes</button>
</div>
import { SaveBar } from "capsomer/react/save-bar";

<SaveBar pending={busy} saved={result?.ok === true} error={result?.ok === false ? "Failed to save. Please try again." : null} />

Examples

Saving

<div class="cap-save-bar">
  <p role="status" class="cap-save-bar-status"></p>
  <button type="button" class="cap-btn" data-variant="primary" aria-busy="true"><span class="cap-btn-spinner" aria-hidden="true"></span><span class="cap-btn-label">Save changes</span></button>
</div>

Saved

<div class="cap-save-bar">
  <p role="status" class="cap-save-bar-status"><span class="cap-status" data-tone="ok"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M8 1a7 7 0 1 0 0 14A7 7 0 1 0 8 1zM3.9 9l3 3 5.2-5.6-1.4-1.4-3.8 4.2-1.6-1.6z"/></svg>Saved</span></p>
  <button type="button" class="cap-btn" data-variant="primary">Save changes</button>
</div>

Failed

<div class="cap-save-bar">
  <p role="status" class="cap-save-bar-status"><span class="cap-status" data-tone="crit"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M5 1h6l4 4v6l-4 4H5l-4-4V5zM7.2 4h1.6v5H7.2zM7.2 10.4h1.6V12H7.2z"/></svg>Failed to save. Please try again.</span></p>
  <button type="button" class="cap-btn" data-variant="primary">Save changes</button>
</div>

No button (nothing to save yet)

<div class="cap-save-bar">
  <p role="status" class="cap-save-bar-status"><span class="cap-status" data-tone="ok"><svg class="cap-status-glyph" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" fill-rule="evenodd" d="M8 1a7 7 0 1 0 0 14A7 7 0 1 0 8 1zM3.9 9l3 3 5.2-5.6-1.4-1.4-3.8 4.2-1.6-1.6z"/></svg>Saved</span></p>
</div>

Saves as it changes (no button), saving

<div class="cap-save-bar">
  <p role="status" class="cap-save-bar-status">Saving…</p>
</div>

Sticky, with another action and Save not yet usable

<div class="cap-save-bar" data-sticky="">
  <p role="status" class="cap-save-bar-status"></p>
  <button type="button" class="cap-btn">Check</button>
  <button type="submit" class="cap-btn" data-variant="primary" aria-disabled="true" aria-describedby="why-save">Save changes</button>
  <span class="cap-btn-reason" id="why-save">Turn on disputes to save these settings.</span>
</div>

API reference

SaveBar

PropTypeRequiredDoes
pendingbooleanA save in flight: the button shows its spinner; with no button the region says "Saving…".
savedReactNodeThe last save worked: true says "Saved"; words say those instead ("Saved.").
errorReactNodeThe last save failed, in words: "Failed to save. Please try again."
submitReactNodeThe button's words.
buttonbooleanFalse leaves the button out: a form with nothing to save yet, or one that saves as each control changes, where the bar only says what happened. The status region stays.
childrenReactNodeAnother action before Save (Check, Cancel, Reset).
disabledReasonReactNodeWhy Save cannot be used yet (a feature that is off): the button stays, aria-disabled, and says why (button.md).
stickybooleanThe bar stays on the window's bottom edge while a long form scrolls.
formstringThe form the button submits, when the bar sits outside it.
namestringThe button's name and value, for a form with several actions posting to one route.
valuestring
classNamestring

Parts and data attributes

ClassIs
.cap-save-barthe root
.cap-save-bar-statusa part
AttributeValues
data-stickypresent or absent

Accessibility

KeyDoes
TabReaches the button after the form's fields
Enter in a fieldPosts the form
  • role="status" is polite: the result is read after what the reader is saying.
  • The result carries its glyph as well as its color (the status component).
  • The button keeps its words while saving and shows the spinner (aria-busy).