Forms
Result
Loading...
Live Editor
function Example() { const [name, setName] = useState(""); const [tried, setTried] = useState(false); const [saving, setSaving] = useState(false); const error = tried && !name.trim() ? "Give the course a name." : undefined; return ( <Card style={{ maxWidth: 480 }}> <form className="ui-stack" onSubmit={(e) => { e.preventDefault(); setTried(true); if (!name.trim()) return; setSaving(true); setTimeout(() => { setSaving(false); toast("Course created", "success"); }, 900); }}> <SectionHeader title="New course" /> <TextField label="Name" placeholder="e.g. Control Engineering" value={name} onChange={(e) => setName(e.target.value)} error={error} /> <Select label="Semester" defaultValue="w"><option value="w">Winter 26/27</option><option value="s">Summer 27</option></Select> <Checkbox label="Invite fellow students" description="You get a link to share afterwards." /> <div style={{ display: "flex", gap: 10, justifyContent: "flex-end" }}> <Button>Cancel</Button> <Button type="submit" variant="primary" loading={saving}>Create</Button> </div> </form> <Toaster /> </Card> ); }
Rules
- Labels above the fields, never only placeholders.
- One column. Fields below each other, in the order in which people think.
- Required is the normal case. Mark the optional ones ("optional" in the hint), not the required ones with asterisks.
- Errors after submitting or when leaving the field – at the field, as a whole sentence that says what to do.
- An error from the server (e.g. no connection) appears as
Notice tone="danger"above the buttons; what was entered stays. - Buttons at the bottom right: Cancel, then the main action.
loadingwhile saving. - What applies at once needs no save button:
Switch,SegmentedControl.