Skip to content

HyTextInput

Usage examples on this page are written for Lit / plain HTML (<hy-text-input>). The same component ships as HyTextInput in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A versatile single-line text input component with enhanced styling and functionality. Supports multiple input types, validation states, icons, and comprehensive accessibility features. Provides a consistent interface for various text input scenarios with built-in error handling. Offers both block (default) and inline layout options — in inline, label sits on the left of the row, input on the right, and helper/error under the control (col 2–end).

Examples

html
<hy-text-input label="Name" placeholder="Enter your name"></hy-text-input>
html
<hy-text-input
  type="email"
  label="Email Address"
  placeholder="user@example.com"
  helper-text="We'll never share your email with anyone"
  required
>
</hy-text-input>

Inline layout (dense parameter panels)

Label on the left, input on the right, helper/error below the row. Set --hy-text-input-label-column-width on a wrapping container so stacked inputs align on the left edge.

html
<div style="--hy-text-input-label-column-width: 8rem;">
  <hy-text-input layout="inline" label="Name" placeholder="Jane Doe"></hy-text-input>
  <hy-text-input layout="inline" label="Email" placeholder="jane@example.com"></hy-text-input>
</div>

API

Properties

PropertyAttributeTypeDefaultDescription
focusedfocusedbooleanfalseWhether the input is currently focused.
disableddisabledbooleanfalseDisables the input, preventing user interaction.
requiredrequiredbooleanfalseMarks the input as required for form validation.
readonlyreadonlybooleanfalseMakes the input read-only, preventing user editing.
errorerrorbooleanfalseWhether the input is in an error state.
leadingIconleading-iconstring''Icon name from HyIcon component library to display before the input field. Uses the HyIcon component for consistent icon rendering across the design system.
trailingIcontrailing-iconstring''Icon name from HyIcon component library to display after the input field. Uses the HyIcon component for consistent icon rendering across the design system.
sizesize'small' | 'medium' | 'large''medium'The size of the input: 'small', 'medium', or 'large'.
layoutlayout'block' | 'inline''block'Row layout: block (default) stacks label above the input; inline puts label on the left and input on the right. Helper/error always sit under the control (col 2–end), never under the label.
widthwidthstring | undefinedundefinedWidth of the input container. Accepts any valid CSS width value (e.g., '300px', '20rem', '50%'). Caps the input field itself; useful in either layout when the default (fill available space) is too wide.
labellabelstring''The label text displayed above the input (block layout) or to the left (inline layout).
valuevaluestring''The current value of the input.
placeholderplaceholderstring''Placeholder text displayed when the input is empty.
helperTexthelper-textstring''Helper text displayed below the input to provide additional context.
typetype'text' | 'email' | 'password' | 'tel' | 'url' | 'search' | 'number''text'The input type: 'text', 'email', 'password', 'tel', 'url', 'search', or 'number'.
namenamestring''The name attribute for form submission.
autocompleteautocompletestring''The autocomplete attribute for browser auto-completion.
autofocusautofocusbooleanfalseMarks this input as the auto-focus target. Read by hy-dialog (and other overlay containers) on show to choose which slotted control receives initial focus. Also focuses on first connect when used outside an overlay, matching the native HTML autofocus attribute — but routed through JS so SSR'd HTML doesn't pull focus during hydration.
autoselectautoselectbooleanfalseAfter auto-focus lands, selects the current value so the user can type-to-replace. Pairs with autofocus for rename-style dialogs where the existing name is shown for context but is meant to be overwritten.
errorMessageerror-messagestring''Error message displayed when the input is in an invalid state.
maxlengthmaxlengthnumber | undefinedMaximum number of characters allowed in the input.
minlengthminlengthnumber | undefinedMinimum number of characters required in the input.
patternpatternstring''Regular expression pattern for input validation.
inputmodeinputmodestring''Virtual-keyboard hint forwarded to the inner input (inputmode), e.g. numeric for one-time codes so mobile users get the number pad while the type stays text (leading zeros, no spinner).
formHTMLFormElement | null
validityValidityState
validationMessagestring

Events

EventDetailDescription
inputFired when the input value changes. Detail:
changeFired when the input loses focus after a value change. Detail:
focusFired when the input receives focus. Detail: none
blurFired when the input loses focus. Detail: none

Slots

SlotDescription
leading-iconOptional slot for custom leading icon content (overrides leading-icon property)
trailing-iconOptional slot for custom trailing icon content (overrides trailing-icon property)

CSS Parts

PartDescription
baseThe text input's base wrapper element
labelThe label element
containerThe input container element
inputThe native input element
leading-iconThe leading icon container
trailing-iconThe trailing icon container
helper-textThe helper text element
error-messageThe error message element

CSS Custom Properties

PropertyDescription
--hy-text-input-background-restBackground color at rest
--hy-text-input-border-restBorder color at rest
--hy-text-input-border-activeFocused edge color, any focus method. Default: var(--hy-border-brand-rest)
--hy-text-input-border-hoverBorder color on hover
--hy-text-input-border-dangerBorder color for error state
--hy-text-input-strokeBorder width
--hy-text-input-radiusBorder radius
--hy-text-input-padding-horizontalHorizontal padding
--hy-text-input-padding-vertical-smVertical padding for small size
--hy-text-input-padding-vertical-mdVertical padding for medium size
--hy-text-input-padding-vertical-lgVertical padding for large size
--hy-text-input-gapGap between input elements
--hy-text-input-container-gapGap between container sections
--hy-text-input-font-familyFont family override for the input value text
--hy-text-input-label-column-widthWidth of the label column in layout="inline" mode. No default — set on a wrapping container so stacked inputs align.
--hy-text-input-height-smOuter height for small size variant. Per-component override in the form-control height contract (see .claude/rules/control-heights.md). Default: var(--hy-control-height-sm)
--hy-text-input-height-mdOuter height for medium size variant. Default: var(--hy-control-height-md)
--hy-text-input-height-lgOuter height for large size variant. Default: var(--hy-control-height-lg)

Methods

focus()

Sets focus on the input.

blur()

Removes focus from the input.

select()

Selects all text in the input.

Built with Lit. Documented with VitePress.