Unsaved Indicator¶
A small dot and text that fades in to flag unsaved changes. Place it in a heading or label.
Decision¶
| When | Use |
|---|---|
| A page with a Change Tracker, which shows and hides it | Unsaved Indicator. |
| A field that saves on change | Nothing. The field saves itself. |
Usage¶
<h2>Settings <span class="stolon-unsaved" id="unsavedIndicator"><span class="stolon-unsaved-dot"></span>Unsaved changes</span></h2>
var tracker = shared.createChangeTracker({ serialize: function () { return JSON.stringify(readForm()); }, indicatorId: 'unsavedIndicator' });
view.addEventListener('input', function () { tracker.check(); });
// after a save: tracker.flashSaved();
Classes: stolon-unsaved, stolon-unsaved-dot.
States and Modifiers¶
stolon-unsavedis hidden (opacity: 0,visibility: hidden) until it hasvisible.save-successturns it to the success color, for the flash after saving.- It is hidden from screen readers while it does not apply. The tracker gives it
role="status"when it has no role, so showing it is announced.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
| Class | What it looks like |
|---|---|
stolon-unsaved |
Inline indicator that fades in to flag unsaved changes |
stolon-unsaved-dot |
Small dot before the unsaved label in the current color |
Example¶
Example Code¶
<!-- title: Unsaved Indicator -->
<h3 style="margin: 0 0 12px;">Settings <span class="stolon-unsaved" id="indicator"><span class="stolon-unsaved-dot"></span>Unsaved changes</span></h3>
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<button type="button" id="btnShow" class="raised stolon-button stolon-small"><span>Show</span></button>
<button type="button" id="btnHide" class="raised stolon-button stolon-secondary stolon-small"><span>Hide</span></button>
<button type="button" id="btnSaved" class="raised stolon-button stolon-secondary stolon-small"><span>Saved Look</span></button>
</div>
<script type="module">
await window.__baseReady;
const indicator = document.getElementById('indicator');
document.getElementById('btnShow').addEventListener('click', () => indicator.classList.add('stolon-visible'));
document.getElementById('btnHide').addEventListener('click', () => indicator.classList.remove('stolon-visible', 'stolon-save-success'));
document.getElementById('btnSaved').addEventListener('click', () => indicator.classList.add('stolon-visible', 'stolon-save-success'));
indicator.classList.add('stolon-visible');
</script>