Skip to content

TextInput

A labeled single-line input covering the common HTML input types, with description, inline error, and decorative prefix and suffix slots.

Import

import { TextInput } from "@hyzer-labs/ui"

Demo

let playerName = $state('');

<TextInput name="player" label="Player name" bind:value={playerName} />

Props

NameTypeDefaultNote
namestringRequired. Form field name.
labelstringRequired. Always in the DOM; sr-only with hideLabel.
type'text' | 'email' | 'password' | 'tel' | 'url' | 'search' | 'number' | 'date' | 'time' | 'datetime-local''text'Date/time types render the native platform picker.
valuestring''Bindable.
placeholderstring
autocompleteHTMLInputAttributes['autocomplete']Native autofill hint, e.g. "email", "name".
maxlengthnumber
patternstringNative validation regex.
inputmodeHTMLInputAttributes['inputmode']Virtual-keyboard hint, e.g. "numeric", "tel".
descriptionstringHelp text below the label.
errorstringInline error message; sets the error state.
requiredbooleanfalse
disabledbooleanfalse
hideLabelbooleanfalse
prefixSnippetDecorative leading content (icon, symbol); rendered aria-hidden.
suffixSnippetDecorative trailing content (unit, icon); rendered aria-hidden.
classstringMerged after the hz-field class.

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-field

Data attributes

HookValuesStyles
data-state'default' | 'error' | 'disabled'The universal field state hook, on the root. Precedence is fixed: error beats disabled.
data-has-prefixpresent when a prefix is setOn .hz-input-wrapper. The reference theme ships no rule for it — it exists so you can, e.g., retune padding when an affix is present.
data-has-suffixpresent when a suffix is setOn .hz-input-wrapper. Same: yours to use.

Part classes

HookValuesStyles
.hz-field-labelchild elementThe label.
.hz-field-requiredchild elementThe required marker.
.hz-field-descriptionchild elementThe hint text.
.hz-field-errorchild elementThe error message.
.hz-input-wrapperchild elementThe bordered box. It carries the border, so prefix and suffix sit inside it.
.hz-input-prefixchild elementThe leading affix.
.hz-input-suffixchild elementThe trailing affix.

Accessibility

The input is associated with its label via id/for. With hideLabel, the label stays in the DOM as screen-reader-only text.

description and error chain into aria-describedby, description first. required sets aria-required, and an error sets aria-invalid.

prefix and suffix are rendered aria-hidden. Keep them decorative, and put any meaning in the label or description instead.

References: MDN: <input>