textbox
textbox is a text field with its label, a help line and an error message wired to it. It
renders a real <input> or <textarea>.
onChange called 0 time(s)
On the root:ui-emptyui-requiredui-readonlyui-disabled
onChange sent: nothing yet
import { computed, state } from '@markless/core';import { textbox } from '@markless/ui';export default function Username() @{ let name = state(''); const typed = computed(() => (name === '' ? 'nothing yet' : name)); <div class="desk"> <textbox.root class="field" name="username" required onChange={(value: string) => { name = value; }} > <textbox.label class="label">Username</textbox.label> <textbox.input class="input" placeholder="ada99" /> <textbox.description class="help">Letters and numbers, no spaces.</textbox.description> <p class="hooks"> On the root: <span class="hook hook-empty">ui-empty</span> <span class="hook hook-required">ui-required</span> <span class="hook hook-readonly">ui-readonly</span> <span class="hook hook-disabled">ui-disabled</span> </p> </textbox.root> <p class="echo"> onChange sent: <span class="echo-text">{typed}</span> </p> </div>;}
.desk { display: grid; gap: 0.9em; width: min(24rem, 100%); font-family: 'Shantell Sans', system-ui, sans-serif; font-size: var(--step--1); line-height: 1.5; color: var(--ink);}.field { display: grid; gap: 0.4em;}.label { font-family: 'Joy Elia', system-ui, sans-serif; font-size: var(--step-0);}.input { box-sizing: border-box; width: 100%; padding: 0.55em 0.8em; border: 1px solid var(--ink); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; font-family: 'Shantell Sans', system-ui, sans-serif; transition: background 140ms ease;}.input::placeholder { color: var(--muted-ink);}.input:hover { background: color-mix(in srgb, var(--purple) 16%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.input:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px;}.field[ui-disabled] .input { opacity: 0.55; cursor: not-allowed;}.help,.echo { margin: 0;}.hooks { display: flex; flex-wrap: wrap; gap: 0.4em; align-items: center; margin: 0.2em 0 0;}.hook { display: none; padding: 0.05em 0.5em; border: 1px solid var(--ink); border-radius: 6px; background: color-mix(in srgb, var(--purple) 26%, var(--cream)); color: var(--ink); font-family: var(--font-mono); font-size: var(--step--1); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.field[ui-empty] .hook-empty,.field[ui-required] .hook-required,.field[ui-readonly] .hook-readonly,.field[ui-disabled] .hook-disabled { display: inline-block;}.echo { padding-block-start: 0.7em; border-block-start: 1px solid var(--ink);}.echo-text { font-family: var(--font-mono);}@media (prefers-reduced-motion: reduce) { .input { transition: none; }}
Click the word Username. Focus moves into the field, because the label's for points at the
input. Type a letter, and ui-empty leaves the list under the field. The root drops it once the
field holds text.
When to use it
Use textbox for free text, such as a name or a message. For one line, use textbox.input.
For several lines, swap it for textbox.textarea, and nothing else changes. For numbers, dates or
codes, look at numberbox, datebox and otp first.
Parts
The text box itself; the label, the control, and any description or error go inside it.
textbox.rootholds the text and the rules, such asrequired. It renders a<div>and no control of its own.textbox.inputis a one-line<input>.textbox.textareais a<textarea>for several lines.textbox.labelnames the field. Clicking it focuses thetextbox.input.textbox.descriptionis a help line. The control points at it witharia-describedby.textbox.erroris the error message. The control points at it too, before the help line.
disabled, required and readonly work on the root or on the control. If either place sets
one, it holds. A control can add a rule the root did not set, but it cannot remove one.
Styling hooks
All of these sit on textbox.root:
| Attribute | Present when |
|---|---|
ui-empty |
The field holds no text. |
ui-required |
required is set on the root. |
ui-readonly |
readonly is set on the root. |
ui-disabled |
disabled is set on the root. |
ui-invalid |
A textbox.error is on the page. |
The control itself gets aria-invalid="true" while a textbox.error is on the page.
Keyboard
The field is a native control, so the browser's own keys apply. The family's tests check these:
| Key | What it does |
|---|---|
Enter in textbox.input |
Submits the form. The text does not change. |
Enter in textbox.textarea |
Starts a new line. It does not submit. |
| Escape | Leaves the text as it is. |
onChange runs once per change, with the whole text so far. It does not run for the text the
field starts with. With an input method editor, the family never writes over the draft. The
characters the person picks are what land.
Gotchas
API reference
textbox.root
valuestringThe text the box shows. Omit it and the box starts empty.Default''.disabledbooleanNobody can type in the control, and it drops out of the tab order.Defaultfalse.requiredbooleanThe control must hold text before a form submits.Defaultfalse.readonlybooleanThe text can be read and selected but not changed.Defaultfalse.namestringSubmitted under this name by whichever control the family renders.Default''.onChange(value: string) => voidCalled with the new text on every change a person makes, once per change, and never for the text the box started with. Omit it and the box still works; the call site simply does nothing.
textbox.description
No props of its own.
textbox.error
No props of its own.
textbox.input
No props of its own.
textbox.label
No props of its own.
textbox.textarea
No props of its own.