Skip to content

Text Input

TextInput Props ​

NameTypeDefaultDescription
modelValuestringRequiredInput value, normally bound with v-model.
labelstringRequiredVisible label. Still names the control when visually hidden.
isLabelHiddenbooleanfalseVisually hides the label and description without removing accessible associations.
descriptionstring—Helper text between the label and control.
isDisabledbooleanfalseDisables the input. Disabled values are excluded from form submission.
isOptionalbooleanfalseShows an optional indicator and takes precedence over isRequired.
isRequiredbooleanfalseShows a required indicator; TextInput also sets aria-required.
labelIconComponent—Vue icon component before the label. The labelIcon slot takes precedence.
labelTooltipstring—Info button beside the label, available on hover, keyboard focus and click.
optionalLabelstringOptionalLocalized optional indicator.
requiredLabelstringRequiredLocalized required indicator.
idstringGeneratedNative input ID. Label and description associations update together.
type'text' | 'password' | 'email'textSingle-line input type. Use a textarea for multiline content.
size'sm' | 'md' | 'lg'mdNeutral heights are 28, 32 and 36px respectively.
isReadOnlybooleanfalsePrevents editing, but remains focusable, undimmed and included in form submission.
disabledMessagestring—Disabled reason. Uses aria-disabled and readonly to preserve focus, while blocking edits and excluding the field from submission.
startIconComponent—Decorative leading icon component. The icon slot takes precedence.
statusTextInputStatus—Error, warning or success, optionally with message and messageId. Error sets aria-invalid.
statusVariant'attached' | 'detached' | 'tooltip'attachedAttached, detached or an icon tooltip. All variants describe the input accessibly.
changeAction(value: string, event: TextInputChangeEvent) => void | Promise<void>—Runs after a value change. A returned Promise automatically drives pending state.
isLoadingbooleanfalseExternal loading state, combined with pending actions without disabling editing.
placeholderstring—Empty-value hint. Does not replace the label.
widthnumber | stringautoWidth of the whole field. Numbers are pixels, CSS strings are used unchanged.
hasClearbooleanfalseShows a clear button for nonempty editable values and restores input focus after clearing.
hasAutoFocusbooleanfalseFocuses the native input after mounting.
htmlNamestring—Native name, taking precedence over a forwarded name and removed when disabled.
autoCompletestring—Forwarded unchanged to native autocomplete.
clearLabelstringClear {label}Localized clear-button name.
loadingLabelstringLoadingLocalized loading-indicator name.

Status type ​

ts
interface TextInputStatus {
  type: 'error' | 'warning' | 'success'
  message?: string
  messageId?: string
}

TextInput Slots ​

NameTypeDefaultDescription
icon() => VNode[]—Decorative leading icon, overriding startIcon. Keep interactive controls out of this slot.
end() => VNode[]—Trailing content, including buttons. Consumers provide accessible names.
labelIcon() => VNode[]—Decorative label icon, overriding the labelIcon prop.

TextInput Events ​

NameTypeDefaultDescription
update:modelValuevalue: string—v-model update, before change and changeAction.
changevalue: string, event: TextInputChangeEvent—Emitted after each committed edit or clear. event.preventDefault() skips changeAction without undoing the model update.
enterevent: KeyboardEvent—Enter outside IME composition. Canceled keydown events suppress it.
keydownevent: KeyboardEvent—Native keyboard event. PreventDefault() can suppress enter.
clearevent: MouseEvent—Clear-button activation. Still emits update:modelValue and change and runs an uncanceled action.
actionErrorerror: unknown, value: string, event: TextInputChangeEvent—Emitted after a synchronous throw or Promise rejection. Pending is cleaned automatically.

TextInputChangeEvent ​

ts
type TextInputChangeEvent = CustomEvent<{
  value: string
  originalEvent: Event
}>
  • Native input events are usually not cancelable.
  • change supplies a cancelable component event.
  • event.detail.value contains the new value.
  • event.detail.originalEvent contains the original event.
  • changeAction and actionError receive the same component event.

The original event type depends on the action:

ActionType
Enter textInputEvent
Confirm input method compositionCompositionEvent
Click the clear buttonMouseEvent

Async actions ​

changeAction receives the new value and component event. Returning a Promise displays a loading indicator.

  • Editing: the input remains editable while saving. Clearing the value also runs changeAction.
  • Loading: aria-busy stays true while any action is unfinished. It clears after all actions settle, including rejected actions.
  • Value updates: new values from the parent take precedence over temporary display values.
  • Concurrent saves: cancel older requests or check request versions in your application to prevent stale results from overwriting newer values.
  • Errors: handle @action-error to show a message. To roll back, update the value bound with v-model.

Template refs ​

Template refs expose these properties and methods:

  • element: HTMLInputElement | null: the native input element, or null before mounting.
  • focus(options?: FocusOptions): focuses the input.
  • blur(): removes focus from the input.
  • select(): selects all input text.

Native attributes ​

  • maxlength, minlength, pattern, required, form, aria-*, data-* and native event listeners are forwarded to the native input.
  • class and style apply to the input wrapper; width applies to the whole Field.
  • The component manages value, type, disabled, readonly, autofocus and core ARIA state. Use the corresponding component props.
  • aria-describedby and aria-labelledby merge with the component's internal association IDs.

Disabled and read-only states ​

  • Disabled without a reason: native disabled prevents editing, focus and submission of the field.
  • Disabled with disabledMessage: aria-disabled and readonly preserve focus so the reason can be discovered. The component removes name and blocks edits and clearing.
  • Read-only: the input remains focusable, allows copying and is included in FormData.
  • Disabled takes precedence when both states are set.

Theme ​

Add a class to the component to override theme variables:

vue
<TextInput v-model="email" class="my-input" label="Email" />
css
.my-input {
  --astryx-input-focus: #10b981;
  --astryx-radius-element: 8px;
}

Appearance and size ​

  • --astryx-input-background: input background color.
  • --astryx-input-border: default border color.
  • --astryx-input-focus: focus border color when no validation status is set.
  • --astryx-radius-element: input corner radius.
  • --astryx-input-height-sm: small height; Neutral defaults to 28px.
  • --astryx-input-height-md: medium height; Neutral defaults to 32px.
  • --astryx-input-height-lg: large height; Neutral defaults to 36px.

Validation states ​

Each state provides three variables for the border and icon, message text, and message background:

  • Error: --astryx-input-error, --astryx-input-error-foreground, --astryx-input-error-background.
  • Warning: --astryx-input-warning, --astryx-input-warning-foreground, --astryx-input-warning-background.
  • Success: --astryx-input-success, --astryx-input-success-foreground, --astryx-input-success-background.

Override status variables on a parent containing the whole field to style both the input and its status message.

Color mode ​

  • Neutral selects its colors from CSS color-scheme.
  • Set data-astryx-color-mode="light" on the root element or theme container to use light mode.
  • Set data-astryx-color-mode="dark" to use dark mode.