Save bar
"You have unsaved changes — Discard / Save" at the foot of a form, shown while the form differs from what it held on load.
Anatomy
div[role=region][aria-label=message][x-data=dsSaveBar][data-ds-dirty?]
│ data-ds-save-bar="floating" once the script runs
├── p icon · message
├── p[role=alert] error error only
├── div
│ ├── ds::button type=reset form=… Discard
│ └── ds::button type=submit form=… Save (loading = saving)
└── span[role=status].sr-only[data-ds-save-bar-status][data-ds-message]
Without the script: a static row at the end of the form, both buttons
native. With it: data-ds-save-bar="floating" turns on sticky while
data-ds-dirty (bottom or top, clear of the safe area) and, without it,
absolute invisible opacity-0 and a 1rem slide, motion-safe. Clean, it is
out of the flow, so a form with nothing to save keeps no gap at its end.
Sticky, not fixed: it stays in the form's column, takes its room at the
end of the form while it is up (it never covers the last field), and sticks
only within its own form's box, so the bars of several forms on one page
never sit on one another.
Dirty
dirty | Who sets data-ds-dirty |
|---|---|
null | dsSaveBar: a FormData snapshot on load, compared after input, change, reset, and when a field's value, name or disabled attribute or the set of fields changes (a hidden input written by a script sets its attribute) |
true / false | the host: rendered by PHP, or toggled by Livewire's wire:dirty.attr="data-ds-dirty"; the script does not watch |
error renders the bar dirty and pins it: the script will not hide it.
Discard is the native reset; the script dispatches discard from the form
after the browser has reset it. guard adds a beforeunload that asks only
while dirty and not on the form's own submit.
Live region
The status inside is emptied and, a frame later, filled with the message
each time data-ds-dirty turns on, whoever set it: one polite announcement
per appearance. It is emptied when the bar hides. Focus is never moved.
Accessibility
| Role | region named by the message; alert for an error |
| Name | Save and Discard by their words |
| Keyboard | Tab to Discard and Save; hidden, it is out of the tab order (visibility) |
| Focus | never taken |
Do not
- Do not move focus to the bar when it appears.
- Do not use
fixed: it would cover the last field and leave its column. - Do not watch
wire:modelfields with FormData: they post nothing by name; usedirtyandwire:dirty.attr.
From the package repo: edit this page on GitHub.