Field
- How
.sdc-fieldaround a<label>with.sdc-field__label, one<input>or<textarea>with.sdc-field__input, and an optional.sdc-field__hintunder it.Field.astrowrites all of it, including the label and hint wiring.- When
- When a page asks a visitor to type something. The first one is the type tester on the MsMadeline font page, where a visitor types a line and sees it in the font. There are no forms on stevendesignco.com itself yet.
- Where
- In the page content, full width of its column. Pair it with a Slider when the visitor also sets a size or an amount, the field first and the slider directly under it.
One size. Padding is --sdc-space-sm on every side and the corners use
--sdc-radius-sm (10px), the control radius the Button uses. The text inside is
--sdc-text-body, 16px, on purpose: iOS zooms the whole page into any field set
smaller than 16px, and the zoom does not undo itself when the field loses focus.
The field takes the full width of its container and is not resizable. Its height
comes from rows on a textarea. A field that the visitor can drag bigger breaks
the layout around it, and the size is the page’s decision.
In code
Section titled “In code”src/components/ui/Field.astro.
---import Field from '../../components/ui/Field.astro';---<Field id="try-text" label="Type something" multiline rows={2} maxLength={100} hint="Up to 100 characters." />| Prop | Type | Default | What it does |
|---|---|---|---|
id |
string | required | Ties the label, and the hint if there is one, to the control. |
label |
string | required | The visible label. It is also the accessible name. |
name |
string | none | The form field name, when the value is submitted. |
value |
string | '' |
The starting text. |
multiline |
boolean | false |
A textarea instead of a single line. |
rows |
number | 3 |
Visible lines, when multiline. |
maxLength |
number | none | The most characters the field accepts. Say the limit in the hint as well, since a silent limit reads as a broken keyboard. |
type |
'text' | 'email' | 'search' | 'url' | 'tel' |
'text' |
The input type for a single line. Phones show the matching keyboard. |
hint |
string | none | One line of help under the control, tied to it with aria-describedby. |
error |
string | none | The validation message. Its presence is what makes the field invalid: it adds sdc-field--invalid, sets aria-invalid="true" and ties the message to the control. |
required |
boolean | false |
Sets required and puts an asterisk in the label. The asterisk is aria-hidden, because required already says it. |
autocomplete |
string | none | The browser autofill hint, such as name or email. Worth setting on anything a person has typed before. |
inputmode |
'text' | 'email' | 'tel' | 'url' | 'numeric' | 'decimal' | 'search' |
none | Which on-screen keyboard to offer. |
disabled |
boolean | false |
Greys the control out and stops it submitting. |
placeholder |
string | none | Shown in an empty control. Never the only label. |
class |
string | none | Extra classes for positioning. |
When both hint and error are set, aria-describedby lists the hint first, so
the help is read before the failure.
Anatomy
Section titled “Anatomy”A grid with --sdc-space-xs between its parts: the label, the control, and the
hint. The label is --sdc-text-body-sm at 600 weight in --sdc-text. The hint is
the same size in --sdc-text-mute. The control is filled with --sdc-surface
and edged with --sdc-rule-strong, so on the page ground it reads as a recessed
panel, the same fill a static card uses.
States
Section titled “States”Rest, hover and focus. Hover darkens the edge to --sdc-text. Focus
is the site-wide ring from Focus. A text field shows
the ring on a mouse click too, which is the browser following :focus-visible:
the visitor is about to type, so the field says it is ready.
Invalid, when error is set. The edge turns --sdc-error at 2px, the message
sits under the control in --sdc-error, and the control takes aria-invalid and
an aria-describedby pointing at the message, so the failure is announced and
never carried by color alone. Write the message as the fix (“Enter an email
address like name@example.com”), not the fault. See Color.
Disabled, when disabled is set. The control fills with --sdc-surface-2,
its text drops to --sdc-text-mute, and it is skipped on submit. Use it rarely:
a control that cannot be used usually should not be shown.
Accessibility
Section titled “Accessibility”- The label is always visible and always above the control, tied with
forandid. A placeholder is not a label: it disappears as soon as the visitor starts typing, and its gray rarely clears 4.5 to 1. - The hint is read after the label through
aria-describedby. - The edge uses
--sdc-rule-strong, which clears the 3 to 1 a control boundary needs on every ground in both themes. The weaker rule token does not. - At 16px, text in the field never triggers the iOS zoom.
Content
Section titled “Content”The label says what to type, in sentence case, in one to three words: “Type something”, “Your email”. The hint says the rule a visitor would otherwise find by hitting it: the character limit, or the format.
Do
- Keep the label visible and above the control.
- Say the limit in the hint when there is one.
- Start a textarea with an example the visitor can edit.
Don’t
- Use the placeholder as the label.
- Make the field resizable.
- Set the text smaller than 16px.
Checks before you ship
Section titled “Checks before you ship”- Click the label. The cursor lands in the field.
- Tab to the field. The site-wide focus ring appears around it.
- Switch to the dark theme. The edge is still easy to see.