Machine-translated – improvements welcome. Suggest an improvement
Button¶
Knopf (button) is the building block for every button (#968, sharpened in #1210). It fixes the kind (main, create, secondary, danger, special form), shows disabled, “working” and the result the same way everywhere and sets aria itself – so that every button shows the same way what it does, whether it is working or why it can't be used. The principles apply to every button.
What it is for¶
A button does something: save, check, create, delete. A way to another page, a file or an address outside is a KnopfLink from the same building block (pattern catalogue C8).
When to use it, when not¶
Use it for every new button – above all for actions that do something on the server (“Check”, “Test”, “… now”). Existing buttons are converted by whoever changes the place anyway; converting all existing code to the principles follows in #1211–#1215. Converted so far: the create buttons of the lists in the Workbench, Library and My account (#989), the buttons “Check”, “Test” and “… now” of the Workbench (#986), the locked buttons “Delete folder” and “Download” (#1210).
Don't use it
- for menu entries (
role="menuitem"), disclosure headers and tiles – they have their own building blocks (Menu, Expander, Tile); for tabs use the building block Tabs; - for ways: use
KnopfLink(to,href); links in running text and into the manual stay<a className="verweis">; - for buttons whose look is fully defined by a design (substitution and administration bars).
Matching patterns in the pattern catalogue: B2 · The result appears where the click happened, B4 · Confirmations in Ablago's own dialog, C6 · “+ …” only where you create something, C8 · A link goes somewhere else, a button does something, C12 · Main button at the bottom, C14 · Kinds of buttons: fixed, the same everywhere, D6 · On the phone.
How to use it¶
| With | How it works |
|---|---|
| Mouse | A click triggers the button. A danger button first opens its confirmation. A button locked for a reason opens the explanation on click (on the button or the ⓘ next to it); a click elsewhere closes it. While a button is working it accepts no second click. |
| Keyboard | Tab reaches every button – also one locked for a reason, so the reason can be heard; a faded button (“nothing to do”) is skipped. Enter and Space trigger it. In the confirmation, focus starts on “Cancel”, Esc cancels. Esc also closes the explanation and returns focus to the button. |
| Touch | Every button has a touch target of at least 44 × 44 px, the small one and the icon-only one, too (On a phone). |
What it means¶
The kind tells the person what a click does – the same everywhere (principles 1–5). A border means “can be clicked”, a solid surface the main action or creating (principle 8).
Kinds¶
| Kind | Looks | What for | Example |
|---|---|---|---|
haupt |
solid blue (accent colour) | the main action of a form or step – at most one per area | “Save number sequence”, “Next”, “Apply”, “Back up now” |
anlegen |
solid green | only starting something new; the label begins with “+” | “+ New”, “+ Post”, “+ Row”, “+ Emergency contact” |
neben |
surface with a border | everything else (default), also “Discard” and “Cancel” | “Test connection”, “Discard changes” |
gefahr |
like secondary, with an icon; text and border turn red only on hover and keyboard focus | something where saved data is lost or someone is locked out – always with a confirmation, which the button asks itself | “Delete”, “Lock immediately”, “Sign everyone out” |
eigen |
special form: no background and no border; shape and colour come from the class of its owner ([data-knopf="eigen"].stern in the file of the area, #1270), never like a link |
column headers, menu entries, stars, handles, tiles, calendar days, permission buttons; components with their own shape such as the expander and the ✕ in the tag use it inside | column header “Name ↕”, star, tile “File your first post” |
Links take you somewhere, actions are buttons (principle 7, pattern catalogue C8, #1277): there is no kind link on Knopf – type checking does not allow it. Whatever does something (“Clear selection”, “Hide”, “Expand all”, “Remove”) is a button of kind neben, small in list headers, rows, bars and messages. A way that should look like a link (“Back to the list”, “Download” in a row) is a KnopfLink art="link".
The colours come from the tokens (--akzent, --gruen, --schlecht) and apply in every design. Colour classes via className (gefahr, gefahr-rand, gruen, primaer) do not exist on the button – the colour comes from the kind; ESLint reports it (ablago/knopf-farben). Size: groesse="klein" in list headers, table rows and bars, otherwise normal. Height (#1589): every button is at least as tall as one line of text with padding – normal --hoehe-bedienung, small --hoehe-bedienung-klein (tokens.css) –, also with an icon only (⋯) and in every state. A select or input in a field has the same height as the normal button; in a row, button, ⋯ and select are equally tall without a rule of their own at that place. On a phone every button has a touch target of at least 44 × 44 px, the small one, too (On a phone).
Solid red is only the confirm button of a confirmation – the moment of decision (principle 5). The building block Confirmation (web/src/bausteine/rueckfrage/) sets it; it does not exist on a page.
Whatever can be undone – taking a link out of a field, removing a row from a list before saving – is not a danger button but a normal “Remove” (kind secondary, small) or an “×”.
“+ New” (#989): If a page has only one thing to create, the button is called exactly “+ New”. If several things can be created on one page, it is “+ New …” with the item, e.g. “+ New key”.
Disabled¶
There are exactly two forms (principle 6):
| Form | How it comes about | How it looks | When |
|---|---|---|---|
| Nothing to do | gesperrt (or gesperrt={!geaendert}) |
faded (disabled), no explanation |
save or discard without changes, empty selection |
| Locked for a reason | gesperrt="<reason>" or gesperrt={{ grund, titel?, eintraege?, weitere?, stattdessen? }} (KnopfSperre) |
dashed border with a padlock (instead of its own icon), a small ⓘ next to it; reachable (aria-disabled) |
delete with links, missing permission, archive mode, “save first” |
A click on the locked button or the ⓘ opens the explanation at the button: in bold the title (default “Not possible right now:”) and the reason, below it the affected entries (eintraege, optionally “and n more”) and under “Instead” the ways that still work – as buttons, never as links; a major step like “Delete with linked folders …” as a danger button with its own confirmation. Esc closes it and returns focus to the button, a click elsewhere closes it, too. It opens above the button – so at the end of a page it doesn't make the page longer; only when there is no room above in the visible area, below. Horizontally it stays on screen.
No long sentence in the row and no reason only in a tooltip (title is invisible on a phone and for screen readers). Dashed means “locked for you” everywhere, like “read only” on a field (pattern catalogue C4). No “?”: that leads to the manual (C7); ⓘ explains exactly this case.
<Knopf gesperrt={{
grund: sperre.grund,
titel: t('…loeschen-nicht-moeglich'),
eintraege: verweise.slice(0, 8).map((r) => <Link to={…}>{r.titel}</Link>),
weitere: verweise.length - 8,
stattdessen: <Knopf groesse="klein" onClick={mitVerknuepften}>{t('…mit-verknuepften-loeschen')}</Knopf>,
}}>{t('mappen.loeschen.knopf')}</Knopf>
Result at the button¶
A result appears where the click happened (pattern B2 in the pattern catalogue, #986): right below the button; in a row of buttons (<div className="knoepfe">) below all buttons of the row, so the buttons stay side by side. Nothing above it moves. If the place is not fully visible, the page scrolls there gently for a new result (without animation with “reduce motion”); a result that is already there when the page opens doesn't make the page scroll (#1027). The result area is always in the document (role="status", empty without taking space), so screen readers announce a new result.
For more than one sentence – a checklist, a text with details – the result goes into an ErgebnisBlock right below the row of buttons:
<div className="knoepfe"><Knopf type="submit" laeuft={laeuft}>{t('…verbindung-pruefen')}</Knopf></div>
<ErgebnisBlock anlass={pruefung}>{pruefung && <PruefungAnzeige p={pruefung} />}</ErgebnisBlock>
Messages about saving stay with the save bar; at the top of the page there are only notices about the state of the whole page.
States¶
| State | How it comes about | How it looks |
|---|---|---|
| mouse over | – | secondary: surface --senke, border --leise; danger: the same plus text and border --schlecht; main and create: surface with --knopf-hover (slightly darker in light mode, slightly lighter in dark mode); KnopfLink art="link": underlined; special form: as its class defines |
| keyboard focus | – | 2 px ring with offset in --akzent; for danger ring, text and border in --schlecht |
| nothing to do | gesperrt |
faded, no hover, disabled |
| locked for a reason | gesperrt="…" or KnopfSperre |
dashed with a padlock, text --leise, ⓘ next to it, explanation on click |
| working | onClick returns a promise, or laeuft |
label invisible in its place, spinner and “Working …” on top – the button keeps its width and place |
| result | return value KnopfErgebnis or ergebnis |
below the button in the style of notices: gut, info, warn, schlecht, with an icon |
| error | the promise fails | like a result schlecht, with the error's message |
Confirmation¶
A danger button asks its confirmation itself: title as a question (“Delete note?”), one or two sentences on the consequences, the verb on the confirm button (“Delete”). Focus starts on “Cancel” (kind secondary) so that Enter destroys nothing; Esc cancels. Only the confirm button is solid red. For very dangerous actions bestaetigeMit asks for a word to be typed. Only after “yes” does onClick run – with “working”, result and error like any button.
Confirmations without danger (such as “Create a new address?”) are asked as before with rueckfrage() from web/src/rueckfrage.tsx; their confirm button is blue. All of them are shown by the building block Rueckfragen, which start.tsx includes once. Everything about the window itself is under Confirmation.
Accessibility¶
The building block sets itself:
aria-busy="true"andaria-disabled="true"while it is working – the button keeps keyboard focus (nodisabled, which would lose focus); the label stays its name, “Working …” is only visible;- for danger
aria-haspopup="dialog"– the button opens the confirmation (role="alertdialog", focus on “Cancel”); - for locked for a reason
aria-disabled="true",aria-describedbypointing to the reason (also while the explanation is closed),aria-expandedandaria-controlsfor the explanation; the ⓘ is called “Why is this locked? aria-describedbypointing to a shown result and a result area withrole="status";- for
nurSymbolaria-labelandtitle; icons themselves arearia-hidden; data-knopfwith the kind – the smoke tests use it on every page they visit: create begins with “+”, danger opens a confirmation, solid red (data-knopf="entscheidung") only in a confirmation (Smoke test and screenshots).
Hover and focus are visible for all kinds in light and dark mode; the pattern page shows them statically, the smoke tests check them with axe-core (including color-contrast).
Code¶
import { Knopf, KnopfLink, type KnopfErgebnis } from '../bausteine';
<KnopfLink to="/werkbank/benutzer/neu" art="anlegen" groesse="klein">{t('werkbank.benutzer.neu')}</KnopfLink>
<Knopf onClick={jetztPruefen} laeuftText={t('…prueft')}>{t('…jetzt-pruefen')}</Knopf>
// Danger: icon and confirmation are required; onClick only runs after “Delete”.
<Knopf art="gefahr" symbol="geloescht" onClick={() => api.notizLoeschen(n.id)}
rueckfrage={{ titel: t('…notiz-loeschen'), text: t('…laesst-sich-nicht-rueckgaengig'), ja: t('…loeschen') }}>
{t('…loeschen')}
</Knopf>
async function jetztPruefen(): Promise<KnopfErgebnis> {
const r = await api.eingangsordnerPruefen();
return { art: 'gut', text: r.uebernommen ? t('…uebernommen', { anzahl: r.uebernommen }) : t('…nichts-gefunden') };
}
Variants¶
| Variant | When |
|---|---|
Knopf |
a <button>: every action |
KnopfLink |
a way that looks like a button (kinds haupt, anlegen, neben) or, with art="link", like a link – never danger. Within Ablago to (e.g. “+ New”, which opens the page for creating); a file to download or an address outside href (#1269) with download or neuesFenster; onClick only with href and only as an aftercare (e.g. reload the list after the download) |
knopfAussehen({ art, groesse }) |
only classes and data-knopf for elements that cannot be a <button>, such as the <summary> of a disclosure (never danger – that needs the confirmation on the button) |
ErgebnisBlock |
detailed result below a button (e.g. a checklist): aria-live, scrolls gently into view |
rueckfrage(), hinweis() |
a confirmation without a danger button (e.g. “Create a new address?”) and a notice window, from web/src/rueckfrage.tsx; shown by the building block Confirmation |
Property (Knopf) |
Meaning |
|---|---|
art |
haupt, anlegen, neben (default), gefahr, eigen (special form with its own class) |
groesse |
normal (default) or klein |
symbol |
icon before the label (name from Symbol.tsx, Lucide); required for danger |
rueckfrage |
only and required for danger: { titel, text?, ja, nein?, bestaetigeMit?, mitGrund? } – title as a question, consequences, verb on the confirm button; mitGrund (true or a suggestion) asks for the reason for the deletion log, onClick(e, anlass) receives it |
onClick |
may return a promise – see Asynchronous handlers; for danger only after “yes” |
gesperrt |
true = nothing to do (faded); a reason as text or a KnopfSperre = locked for a reason (dashed, padlock, ⓘ) – see Disabled |
laeuft, laeuftText |
“working” from outside (form is sending, job in the background) and its text (default “Working …”) |
ergebnis |
result from outside, e.g. when a background job has finished |
nurSymbol |
icon-only button: the name for screen readers (required) and the tooltip at the same time |
ref, type, others |
as with <button>; default type is button (danger and locked for a reason are always button) |
Type checking does not allow art="gefahr" without rueckfrage or without symbol, nor rueckfrage on another kind (web/src/bausteine/knopf/typpruefung.ts pins this down).
Asynchronous handlers¶
onClick may be async. The button
- shows “working” at once (
aria-busy="true") and accepts no second click – not even via Enter in a form field; - then shows what the promise returns if it is a
KnopfErgebnis({ art, text }); anything else (e.g.true) it doesn't show; - catches an error and shows it right at the button instead of letting it vanish in the console. This is the shared way for asynchronous handlers in the interface (#1011).
The error text is the interface's message; without one it says “That didn't work. Please try again.”
Without a button – onSubmit of a form, onChange of a checkbox, an event on the window – use abfangen from ../bausteine. It returns no promise to React and passes an error to the message the place already has; if it has none, it appears as a notice window. The handler starts right away, so e.preventDefault() at the beginning works as usual.
<form onSubmit={abfangen(speichern, (text) => setMeldung({ art: 'schlecht', text }))}>
<input type="checkbox" onChange={abfangen(async (e: ChangeEvent<HTMLInputElement>) => { … })} />
ESLint checks this strictly (@typescript-eslint/no-misused-promises, no-floating-promises); since #1011 there is no exception for the interface in eslint-suppressions.json any more. A loading function that shows its errors itself is attached to an event or timer with () => void laden().
Right and wrong¶
| Right | Wrong |
|---|---|
<KnopfLink to="…/neu" art="anlegen" groesse="klein">+ New</KnopfLink> |
“+ New” in blue or as “New user” |
<Knopf art="haupt" type="submit">Save</Knopf> – one main button per form |
a green “Save”, three blue buttons side by side |
<Knopf art="gefahr" symbol="geloescht" rueckfrage={…}>Delete</Knopf> |
<Knopf className="gefahr-rand">, a red text link “Delete”, danger without a confirmation |
| “Discard” as a button with a border next to the main button | “Discard” as a red link or with a confirmation on click |
gesperrt={!geaendert} – nothing to do |
gesperrt={!geaendert && 'Nothing changed'} – that needs no explanation |
gesperrt={verwendet && t('…wird-noch-verwendet')} |
disabled title="Still in use" or a sentence next to the button |
result at the button (return value or ErgebnisBlock) |
result at the top of the page while the button is at the bottom |
<Knopf nurSymbol={t('…neu-laden')}><Symbol name="neu-laden" /></Knopf> |
an icon button without a name |
<KnopfLink to="…" art="link">Back to the list</KnopfLink> |
<Knopf art="link" onClick={…}> – no longer exists; an action that looks like a link |
<KnopfLink href={url} download groesse="klein">As PDF</KnopfLink> |
<a className="knopf klein" href={url}> – ESLint reports it (ablago/bausteine) |
<Knopf groesse="klein" onClick={leeren}>Clear selection</Knopf> |
“Clear selection” as a text link |
Files and tests¶
- Building block:
web/src/bausteine/knopf/Knopf.tsx, explanation when locked:Erklaerung.tsx, look:Knopf.module.css(basic shape, colours and states per kind; global button classes such as.knopf,.primaeror.textknopfno longer exist since #1270 – surroundings adjust a button via[data-knopf="…"]) - Confirmation:
web/src/bausteine/rueckfrage/Rueckfrage.tsx(window, preview for the pattern page), queueweb/src/rueckfrage.tsx– see Confirmation - Pattern page:
web/src/bausteine/knopf/muster.tsx; type check:web/src/bausteine/knopf/typpruefung.ts - Lint:
ablago/knopf-farbenandablago/bausteine(alsoknopf/textknopfon<a>,<Link>,<label>,<span>, #1269) in.github/werkzeuge/eslint-ablago.mjs(testeslint-ablago.test.mjs) - Tests:
web/test/baustein-knopf.test.ts(renders with react-dom/server and checks kinds, danger, disabled in two forms,aria-*anddata-knopf); smoke tests inweb/rauchtest/bereiche/bausteine-und-knoepfe.mjs: button on the pattern page (working, result, error; danger with a confirmation; locked with an explanation), the guard on every page, “+ New” in lists (#989), inbox folder “Check now” (#986)

