Example#
Only for replies.
Usage#
Wrap every form control in a Field: it prints the label, the hint and the error, and wires them to the control with ids, aria-describedby and aria-invalid. Groups of radios or checkboxes use Fieldset.
- Required and optional. Optional fields print "(optional)" after the label; required ones are not marked, because most fields in a short form are required.
- Errors.
errorprints a server message;messagesoverrides the default validation messages per check. The error line is always in the markup, empty and hidden until used. - Layout.
orientation="horizontal"puts a 14 rem label column beside the control from md. - Ids come from
idPrefixandname, with no hooks, so fields render on the server.
Anatomy#
Only for replies.
Add your email, so I can reply.
- LabelField-label role, 16 px, weight 600.
.mk-field-label - HintMeta role, read with the control.
.mk-field-description - ControlOne control element.
.mk-input - ErrorThe error glyph and a literal message.
.mk-field-error
Volume#
Reading layer: identical at every volume.
Quiet
Only for replies.
Add your email, so I can reply.
Studio
Only for replies.
Add your email, so I can reply.
Press
Only for replies.
Add your email, so I can reply.
Rave
Only for replies.
Add your email, so I can reply.
Content#
- Labels are nouns: "Email", "Your current website". No colons.
- Hints say why or how: "Only for replies."
- Errors say what to do in the field's words: "Add your email, so I can reply."
Do and don't#
Do
Add your email, so I can reply.
Don't
Error: invalid value.
Accessibility#
- The control gets
id,name,required,aria-describedby(description and error) andaria-invalid. - Optional fields are marked "(optional)"; required ones are not.
- Errors print a glyph and words in the text colour, never red.
| Keys | What happens |
|---|---|
| Tab | Moves focus to the field's control; its label, description and error are announced |
The colour pairs it prints, with their contrast on both papers:
| Text | Surface | Role | Bone | Night |
|---|---|---|---|---|
--mk-ink | --mk-paper | body | 16.49:1 · Lc 97.4, passes | 16.21:1 · Lc 96.1, passes |
--mk-ink | --mk-paper | body-ui | 16.49:1 · Lc 97.4, passes | 16.21:1 · Lc 96.1, passes |
--mk-ink | --mk-paper | long | 16.49:1 · Lc 97.4, passes | 16.21:1 · Lc 96.1, passes |
--mk-ink | --mk-paper-sunken | body | 15.20:1 · Lc 92.2, passes | 15.53:1 · Lc 95.7, passes |
--mk-ink | --mk-paper-sunken | body-ui | 15.20:1 · Lc 92.2, passes | 15.53:1 · Lc 95.7, passes |
--mk-ink | --mk-paper-sunken | long | 15.20:1 · Lc 92.2, passes | 15.53:1 · Lc 95.7, passes |
--mk-ink | --mk-paper-plate | body | 18.42:1 · Lc 105.1, passes | 15.02:1 · Lc 95.4, passes |
--mk-ink | --mk-paper-plate | body-ui | 18.42:1 · Lc 105.1, passes | 15.02:1 · Lc 95.4, passes |
--mk-ink | --mk-paper-plate | long | 18.42:1 · Lc 105.1, passes | 15.02:1 · Lc 95.4, passes |
--mk-ink-2 | --mk-paper | meta | 7.21:1 · Lc 80.3, passes | 12.18:1 · Lc 77.4, passes |
--mk-ink-2 | --mk-paper-sunken | meta | 6.65:1 · Lc 75.1, passes | 11.67:1 · Lc 77.0, passes |
--mk-ink-2 | --mk-paper-plate | meta | 8.06:1 · Lc 87.9, passes | 11.29:1 · Lc 76.6, passes |
--mk-on-control-2 | --mk-control | body-ui | 6.59:1 · Lc 82.6, passes | 12.47:1 · Lc 82.8, passes |
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
label required | ReactNode | none | Required: the visible label. |
name required | string | none | Required: posts with the form and derives the ids. |
description | ReactNode | none | |
error | string | none | A server message (20 §8); `Form` writes client messages into the same line. |
required | boolean | none | |
optionalLabel | string | "(optional | Shown when the field is not required (default "(optional)"). |
idPrefix | string | none | |
messages | Partial<Record<ValidityKey, string>> | none | Literal messages per validity state, overriding Form's defaults. |
orientation | "horizontal" | "vertical" | none | Horizontal from the md width: a 14rem label column. |
children required | ReactElement<unknown, string | React.JSXElementConstructor<any>> | none | One control element (Input, Textarea, Select, Slider, Switch, a native control). |
Tokens#
System tokens (14)
Changelog#
Arrived in 0.1.0.
- The reading layer's controls, overlays, forms and visitor prefs (P2-T1 to P2-T5): every Button is the comic hit key, with IconButton, Link and Tooltip; Input, Textarea, Select, Checkbox and CheckboxGroup, Radio and RadioGroup, Switch, Slider with the ruler, RulerReadout and SegmentedControl; Dialog, Drawer, NavSheet, Tabs, Disclosure, Faq and faqJsonLd on Base UI 1.9 where the platform falls short; Field, Fieldset, Form with the site's inline validation, ErrorSummary, Callout, Honeypot, FormTimestamp and QuoteForm; PrefsScript under 1 KB, usePref and setPref with cross-tab sync, ThemeToggle and the visitor VolumeDial; VisuallyHidden.