Text-like native inputs: text, email, search, tel, url, and similar.
Labels and messages belong to Field. For several lines, use
TextArea; for passwords, Password Input.
| Item | Requirement |
|---|---|
| CSS | input.css; field.css for a label and messages |
| Element | <input class="hinput" type="…"> with a text-like type |
| Parts | None. To mark parts of the text, on a text, email, tel, or url field: .hinput-highlight around it, and .hinput-highlight-backdrop after it, aria-hidden, holding a <span> with the text |
| Required | A name: a <label for> matching its id, or aria-label |
| Unique | Its id |
| Script | Only to mark parts of the text; see What a script does |
<input class="hinput" id="company" name="company" type="text" placeholder="Acme Inc." aria-label="Company" />To mark parts of the text, such as the variables in a template:
<div class="hinput-highlight">
<input class="hinput" id="subject" name="subject" value="Hello {{1}}" aria-label="Subject" />
<div class="hinput-highlight-backdrop" aria-hidden="true"><span>Hello <mark>{{1}}</mark></span></div>
</div>| Hook | Effect |
|---|---|
placeholder |
Shown in --harmo-color-text-tertiary |
aria-invalid="true" |
--harmo-color-danger border, and a red ring when focused |
readonly |
Secondary background; still focusable and copyable |
disabled |
Secondary background, no shadow, and --harmo-color-text-tertiary text |
.hinput-highlight |
Marks parts of the text, drawn over the field |
--harmo-control-height(34px) tall, 10px (--harmo-space-xs) inline padding, 14px text on a fixed 20px line, so the height doesn't depend on the font. Every text field and select trigger starts its text at the same inset, so they line up in a form.- Fills its container (
inline-size: 100%) and can shrink to any width. Next to a button in a flex row, the input takes the room the button leaves. - Border: 1px
--harmo-input-color-border(#e3e8ee) with--harmo-input-box-shadow, a faint layered shadow. - Hover (hover devices): the border turns
--harmo-color-focusover 150ms (--harmo-duration-fast), except on disabled, read-only, and invalid controls. Only the pointer on the control itself does this: browsers count a control as hovered while its<label>is, so a Field's.hlabelunder the pointer leaves it as it is. - Focus: the border turns
--harmo-color-focus. With:focus-visible, which browsers match whenever a text field is focused, a 3px ring of the same color at 20% appears, starting at the border. - Selects and textareas share this box and these states, so they always match; segmented options share the border.
type="search": the browsers' own clear button and decorations are hidden, so every browser shows the same field. For a magnifier and a clear button of Harmo's, use Search.- Marked text is
--harmo-color-primaryon a see-through 14% of it, with 2px corners. The field's own text is see-through, with the text drawn over it taking its place; the caret, selection, and placeholder are still the field's, and presses reach it. A selection is a see-through--harmo-color-focus, so the text over it stays readable. - In forced-colors mode, the field shows its own text and only the marks are
drawn, in the system's
Highlight.
- Name it with a
<label for>in a Field, and connect a description and error witharia-describedby. - Set
aria-invalid="true"only after the application has validated the value, and give fields anautocompletevalue where one fits. - The default border is 1.23:1 on white, a deliberately light look, and the
faint shadow doesn't add to it. W3C's Understanding of WCAG 1.4.11 says a
control needs no visible boundary unless the boundary is its only cue, so
the light edge meets 1.4.11 only beside a visible label, as in a
Field, or another visible cue, such as Search's
magnifier. For a field with neither, named only by
aria-labelor a placeholder, set--harmo-input-color-border: var(--harmo-color-border-control), 3.42:1, on:rootor on what's around it. Selects and textareas follow, since they share the token. - Marks are only seen: a screen reader reads the field's value. If they mean something, such as a variable that must be filled in, say so in its label or description.
None, unless it marks parts of the text:
| Change | When |
|---|---|
The text and <mark>s in the backdrop |
As the value changes |
| The backdrop's size, type, padding, and direction, copied from the field | As the value changes or the field resizes |
The scrollLeft of the backdrop's <span> |
As the field scrolls |
examples/html/src/scripts/highlight.js is an example script.
<Input> renders the <input>. In a Field, it takes the
field's id and descriptions. Its props are the input's attributes, and:
| Prop | Effect |
|---|---|
highlight |
A regular expression: what it matches in the text is marked as you type, with or without its g flag. Only on a text, email, tel, or url field; on any other type it's ignored, so a password stays hidden |
With highlight, the <input> is inside .hinput-highlight, which fills its
container as an input does. Other props stay on the <input>, so layout such as
flex or gridColumn needs an element of your own around it.
Adding or removing highlight on a field already showing replaces the
<input>, so it loses focus and any text not held in value. To turn marks off
and on in place, keep the prop and pass a pattern that matches nothing, such as
/$^/.
<Field label="Billing email" error="Enter a valid email address.">
<Input name="billing-email" type="email" autoComplete="email" />
</Field>
<Field label="Subject">
<Input name="subject" highlight={/\{\{\d+\}\}/g} />
</Field>--harmo-color-primary, --harmo-border-radius, --harmo-color-background-secondary,
--harmo-color-danger, --harmo-color-focus, --harmo-color-text,
--harmo-color-text-tertiary, --harmo-control-height,
--harmo-duration-fast, --harmo-font-family, --harmo-font-size-sm,
--harmo-font-weight-normal, --harmo-input-box-shadow,
--harmo-input-color-background, --harmo-input-color-border,
--harmo-space-xs.