Overview Button Copy button Field Input Number field Textarea Select Combobox Multiselect Date picker Date range picker Date-time picker Checkbox Radio group Position picker Switch Slider Dropzone Device controls Avatar Badge Card Collapsible Kbd Map Matrix Proportion bar Separator Stat Table Timeline Chat Playback Pagination Charts Chart theming Profile chart Time series chart Bar chart Isopleth chart TS diagram Box plot Rose chart Calendar chart Banner Toast Loader Progress Skeleton Empty state Error state Dropdown menu Tooltip Info tooltip Dialog Sheet Resizable Confirm dialog Breadcrumbs Command palette Mobile menu Navigation list Outline Scroll rail Sidebar Tabs
Field
A label over a control, with help text or an error under it. The control inside is wired up for you: its id, what describes it, and whether it's invalid.
Example
Make it 9 digits and the error goes away.
An MMSI is 9 digits.
<Field label="MMSI" description="From the vessel's radio licence." {error}>
<Input bind:value={mmsi} inputmode="numeric" />
</Field> Validation
Send it empty. Each field shakes once as its error appears; sending again shakes what's still wrong and puts the cursor in the first.
<form bind:this={form} onsubmit={submit} novalidate>
<Field label="Name" error={errors.name}>…</Field>
</form>
function submit(event) {
event.preventDefault();
tried = true;
// Shakes every invalid field and focuses the first. False when all is well.
if (shakeInvalid(form)) return;
save();
} A form
Rules
- Label above the control, always. Next to it only in a settings row, where the control is a switch or a short select.
- Mark the optional fields, not the required ones: most fields are required.
- Help text says what the label can’t: the format, a limit, who sees it. Leave it out when there’s nothing to add.
- An error says what’s wrong and how to fix it, and shows after the field is left or the form is sent, not while typing the first character.
- A failed submit shakes the invalid fields and focuses the first, with shakeInvalid(form). Don’t just disable the submit button: people can’t tell what’s missing.
- Fields in a form are 24px apart. First and last name can share a row; other fields don’t.