Settings that save themselves
Apply simple on/off settings the moment they change and confirm with a toast; save groups of related fields with one button.
The problem
Settings pages mix two models. Some switches save straight away, some fields wait for a Save button at the bottom of the page, and nothing tells people which is which. They change a setting, leave, and lose it, or press Save on a page that already saved.
When to use it
Use it for
- Preferences and settings pages: notifications, privacy, workspace settings.
- Any screen where people change a few values and then leave.
Not for
- Changes that are expensive or affect other people, like payroll rules: use a form with Save and a confirmation.
- Multi-field records where the fields only make sense together, like an address.
Anatomy
- SectionsVerticalTab or Tab per area: Profile, Notifications, Security.
- Instant settingsSwitchField, SegmentedControl. Each change saves on its own and shows a short Toast.
- Saved groupsRelated text fields in a form with its own Save button, right below the group.
- FailureIf an instant save fails, put the switch back and show an error Toast with a retry.
How to build it
- Sort each setting into instant (on/off, a choice) or saved (text fields, related values).
- Use SwitchField for instant settings and save each change straight away.
- Confirm each instant save with a polite Toast: “Leave emails turned off”.
- Group saved fields into a form with its own Save button directly below it, not at the bottom of the page.
- Never mix both models in one section. A section is either instant or has a Save button.
- If people leave a saved group with unsaved changes, ask before throwing them away.
app.tsx
import { SwitchField, useToast } from "@nexera-ui/react";
export function LeaveEmails({ initial }: { initial: boolean }) {
const toasts = useToast();
const [on, setOn] = useState(initial);
return (
<SwitchField
label="Email me about leave requests"
description="When someone on your team applies or cancels"
isSelected={on}
onChange={async (next) => {
setOn(next);
try {
await saveSetting("leaveEmails", next);
toasts.add({ title: next ? "Leave emails turned on" : "Leave emails turned off" });
} catch {
setOn(!next);
toasts.add({ title: "Couldn't save. Try again.", tone: "danger" });
}
}}
/>
);
}Accessibility
| Key | Action |
|---|---|
| Space | Turns the focused switch on or off. |
| Arrow keys | Move between settings sections in the tab list. |
| Enter | Submits a saved group when focus is in one of its fields. |
- A switch announces its new state when it changes; the toast confirms that it was saved.
- Each saved group is a form with its own heading, so its Save button is clearly its own.
- Don't disable Save until something changes; explain instead, or people can't find out why.
Do and don't
DoApply switches immediately and confirm with a short toast.
Don'tMake people press Save after flipping a switch.
DoPut the Save button directly under the fields it saves.
Don'tPut one Save button at the bottom of a long page of tabs.
DoPut the switch back and say so when saving fails.
Don'tLeave the switch on when the setting didn't save.