Machine-translated – improvements welcome. Suggest an improvement
Field¶
Feld (field) is the frame around every input (#967). It sets the label, hint, error message and help icon and links them for screen readers – so that every field looks the same and says the same way what is wrong and where to find help.
What it is for¶
Wherever someone enters or chooses something: text, number, date, drop-down list, multi-line text, password, checkbox. The input itself can be a building block that sits in the frame (Date, Inputs with a unit, Multiple selection).
When to use it, when not¶
Use it for every new input in a form – also for a single field in a dialog. Existing forms are converted by whoever changes them anyway (so far: package settings and the settings when installing a package).
Do not use it
- for search boxes in a toolbar without a visible label (use
aria-labelon the box there; lists have the Search); - for inputs in table cells (the column header is the label);
- for plain displays without input – use property lists (
<dl class="eigenschaften">); - as a frame around several independent fields – each field gets its own frame; inputs that belong together under one label are a
FeldGruppe; - for something that is on or off (a function, a service) – that is a Switch; the checkbox stays for choices and options (pattern catalogue A7).
Matching patterns in the pattern catalogue: A3 · Phrase things positively, A4 · What someone enters stays as it is, A5 · Number and choice fields check immediately, A6 · Required only when really needed, A7 · Switch or checkbox, B6 · Calm error messages, C4 · Form rows, C7 · Help “?” in the heading.
How to use it¶
| With | How it works |
|---|---|
| Mouse | A click on the label puts the focus into the input; for a checkbox the label toggles it, too. The “?” after the label opens the matching place in the manual in a new tab. |
| Keyboard | Tab moves from input to input in the visible order; the “?” is a stop of its own. A checkbox toggles with Space. What is wrong is heard when entering the input (error, then hint). |
| Touch | Inputs and drop-down lists are at least 44 px high, the whole row of a checkbox too; the “?” has an invisible touch target of 44 × 44 px (On a phone). Number fields bring up the matching on-screen keyboard with inputMode. |
What it means¶
Structure¶
Every field uses the same rows (basic rule “form rows” in the pattern catalogue, #801):
- Label – short, without a colon; followed if needed by “(optional)” and the help icon “?”.
- Input – text box, drop-down list, multi-line box …; a checkbox sits in this row together with its label.
- Error – what is wrong and how to put it right, in the error colour with a warning icon. It sits directly below the input, where the eye is: a long hint cannot push it away – on a phone not under the keyboard either – and the visible order is the same as the order read aloud.
- Hint – a permanent explanation in quiet type. For a checkbox, its description goes here.
For the person this means: red is an error that says how to put it right. Dashed means “cannot be changed here” – read only, calculated, combined or protected; below it says why. Faded means disabled. “(optional)” means voluntary; everything else is required.
Behaviour¶
- Required is the normal case and is not marked; voluntary fields get
optional. This also applies to package settings: fields withoutpflichtin the manifest show “(optional)”; there is no asterisk. - Only show errors when they are right: after saving or once the input is definitely wrong – not on the first keystroke in an empty field.
- The message says how to put it right: “Please enter exactly five digits.” instead of “Invalid”.
- The hint stays when an error is added; the error goes above it, directly below the input (state “Error with hint” on the pattern page).
- The help icon opens the matching place in the manual of the installed version in a new tab (component
Hilfe).
States¶
| State | How it comes about | How it looks |
|---|---|---|
| empty, filled | value of the input | border in --rand-eingabe (at least 3:1, #1026) |
| mouse over | – | border in --leise (not when disabled or read only) |
| keyboard focus | – | border and focus ring in --akzent |
| error | fehler set |
border and message in --schlecht, warning icon; the focus ring then also in --schlecht |
| error with hint | fehler and hinweis set |
message directly below the input, the hint below it |
| disabled | disabled on the input |
surface --senke, text --leise, weaker border --linie-stark, no hover |
| read only | readOnly on the input |
surface --senke, dashed border, text easy to read and select |
| calculated, combined, protected | NurLesenFeld with herkunft |
like “read only” (surface --senke, dashed border in --rand-eingabe), with the origin and an icon in --leise underneath – one look, only the sentence differs (“calculated by Verträge”, “no longer calculated …”, “made up of …”) |
| optional | optional |
“(optional)” in --leise after the label |
Accessibility¶
The frame sets automatically:
idon the input andhtmlForon the label – a click on the label focuses the input, screen readers read the name;aria-describedbyon the input: first the error message, then the hint (the input's own values stay in front);aria-invalid="true"while an error is set;- an error area with
aria-live="polite"that is always in the document (empty, without height). A new message is announced without interrupting the person. Deliberately norole="alert": after saving with several errors, every field would otherwise interrupt separately; - “(optional)” as part of the name (“Phone (optional)”);
- the help icon next to, not inside,
<label>– otherwise the field would be called “Phone Help on …”; - for
FeldGruppe,role="group"witharia-labelledbypointing to the label, hint and error viaaria-describedbyon the group.
Errors are never shown by colour alone: the message is text with a warning icon in front. Hover and keyboard focus are visible in light and dark. The pattern page checks this in the smoke tests with axe-core.
Code¶
import { Feld, HakenFeld, FeldGruppe } from '../bausteine';
<Feld beschriftung={t('…plz')} hinweis={t('…plz.hinweis')} fehler={plzFehler} hilfe="einrichtung.konto">
<input type="text" inputMode="numeric" value={plz} onChange={(e) => setPlz(e.target.value)} />
</Feld>
| Property | Meaning |
|---|---|
beschriftung |
visible name of the field (required) |
hinweis |
explanation below the input; a list gives several lines |
fehler |
error message; empty (null, undefined, '') means no error |
hilfe |
place in the manual from shared/src/hilfe.ts – the “?” after the label |
optional |
marks a voluntary field with “(optional)” |
id |
id of the input; if not given, the element's own, otherwise a generated one |
beschriftungVerbergen |
label for screen readers only – where the row already says what it is about (e.g. the archive number on a document) |
kopfZusatz |
something small to the right of the label, e.g. the link kind of a link field |
anker |
jump target for tours and tips (data-anker), also on HakenFeld and FeldGruppe |
The input can also be a function: <Feld …>{(v) => <input {...v} />}</Feld> – v carries id and aria-describedby, for inputs inside own components. Text, number, date and select (without multiple) have the same height.
Variants¶
| Variant | When | Input |
|---|---|---|
Feld |
text, number, date, drop-down list, multi-line, password | exactly one element |
HakenFeld |
a single checkbox (yes/no) | <input type="checkbox"> – sits before the label |
FeldGruppe |
several inputs under one label: checkboxes of a multiple choice, radio buttons, a stored secret with buttons | any number, each with its own label |
NurLesenFeld |
a value that cannot be changed here: calculated by a package (#1034), combined (#1050), protected | none – the value as content, its origin (herkunft, with symbol) underneath |
If the input does not take the links as props (its own component that passes them on to an inner element), pass a function: <Feld …>{(v) => <ZahlEingabe v={v} … />}</Feld>. v contains id, aria-describedby and aria-invalid.
Right and wrong¶
| Right | Wrong |
|---|---|
<Feld beschriftung="Name"><input …/></Feld> |
<label>Name</label><input …/> without htmlFor and id |
<Feld beschriftung="Phone" optional> |
“Phone*” on all other fields |
hilfe="einrichtung.konto" – the “?” at the label |
a “?” below the field or in the message |
fehler="Please enter exactly five digits." |
fehler="Invalid" or just a red border |
<HakenFeld beschriftung="Reminder by email" hinweis="On the day before the appointment."> |
writing the checkbox's description into its label |
<FeldGruppe beschriftung="Weekdays"> with one <label className="haken"> each |
one <label htmlFor> for several checkboxes |
| a new variant in the building block if something is missing | overriding the frame's spacing or colours on a page |
Files and tests¶
- Building block:
web/src/bausteine/feld/Feld.tsx, look:Feld.module.css - Pattern page:
web/src/bausteine/feld/muster.tsx - Test:
web/test/baustein-feld.test.ts(renders with react-dom/server and checksid,htmlFor,aria-describedby,aria-invalid) - First users:
Eingabeinweb/src/werkbank/PaketEinstellungen.tsx(Workbench → Packages → Settings and when installing)



