Textfield
Enter and edit text.
Textfield
Usage
import { Textfield } from "@bedform/ui/textfield";
import { useState } from "react";
export function WorldNameField() {
const [value, setValue] = useState("");
return (
<Textfield
name="world"
label="World name"
description="Shown to other players"
placeholder="New World"
value={value}
onChange={(event) => setValue(event.currentTarget.value)}
/>
);
}Textfield renders the label, the framed native input, and the description and error text. It links them with id and aria-describedby, generating an id when you do not pass one.
Validation
Use native input constraints for validation. Set error to show a custom message: Textfield passes it to setCustomValidity(), sets aria-invalid, and connects the visible message with aria-describedby.
<Textfield label="Seed" name="seed" type="number" required />
<Textfield label="World name" name="world" error="This name is already in use" />Events
Textfield uses the native input, change, focus, blur, and form events of its <input>, so onChange, onInput, onFocus and onBlur work as on any input. Its value is the input's native value, and its ref points to the input.
API
Textfield passes every input attribute to the native <input>, such as autoComplete, inputMode, list, name, value, type, placeholder, min, max, step, minLength, maxLength, pattern, required, readOnly, disabled and id. className and style apply to the root element instead.
| Prop | Type | Default |
|---|---|---|
description | string | — |
error | string | — |
label | string | — |
Public classes
| Class | Purpose |
|---|---|
.ore-textfield-label | Visible label |
.ore-textfield-control | Input frame |
.ore-textfield-input | Native input |
.ore-textfield-icon | Leading icon |
.ore-textfield-description | Supporting text |
.ore-textfield-error | Validation message |
CSS variables
| Variable | Purpose |
|---|---|
--ore-textfield-unit | Base size unit |
--ore-textfield-background | Input background color |
--ore-textfield-shadow | Bottom shadow color |
--ore-textfield-border | Border color |
--ore-textfield-foreground | Label text color |
--ore-textfield-input-foreground | Input text color |
--ore-textfield-description | Description text color |
--ore-textfield-error | Error text and border color |
--ore-textfield-caret | Text caret color |
Accessibility
Use a visible <label for="..."> for every input whenever possible. The for value must match
the input id, and the input remains the accessible control and form participant. Use
aria-label only when a visible label is not appropriate.
Give supporting text an id and reference it from aria-describedby. For a visible validation
message, reference the error element from the same attribute and set aria-invalid="true" while
the value is invalid. Keep the browser's validity state as the source of truth with native
constraints or setCustomValidity().
disabled removes the input from focus and form submission. readonly keeps it focusable and
submittable while preventing edits. Use a surrounding <fieldset disabled> when a group of
fields must be disabled together.