Text Input

Alignment target:@astryxdesign/core v0.7.1 · TextInput

Usage #

TextInput accepts single-line text. The component includes Field.

Vue
<script setup lang="ts">
import { TextInput } from '@astryx-vue/core/TextInput'
import { shallowRef } from 'vue'

const email = shallowRef('')
</script>

<template>
  <TextInput v-model="email" label="Email" type="email" auto-complete="email" />
</template>

For a custom control, use Field. Import the theme once in your app entry:

TypeScript
import '@astryx-vue/themes/neutral.css'

Anatomy

ElementDescription
LabelText that identifies the field. Always rendered for accessibility even when visually hidden.
DescriptionHelper text between the label and the input that provides additional context or formatting hints.
Start iconA leading icon inside the input that hints at the expected content, like a magnifying glass for search.
PlaceholderHint text shown when the input is empty. Disappears on focus.
Clear buttonA trailing × button that resets the value and returns focus to the input.
SpinnerLoading indicator that appears during async actions like server-side validation.
Status iconA trailing icon (error, warning, or success) that communicates validation state.

Best practices #

GuidancePractices
DoAlways provide a visible label so users know what the field is for. Only hide the label when surrounding context makes it obvious, like a search bar with a magnifying-glass icon.
DoUse validation status with a message to explain what went wrong: "Email must include @" is better than just turning the border red.
DoSize the input to match the expected content length so users can gauge how much to type: small for zip codes, medium for names, large for URLs.
DoAdd a clear button for search and filter inputs so users can quickly reset without selecting all text.

Examples #

Text Input — Icon

Open in Playground

Name, email, and password fields with a leading icon.

Text Input — Search

Open in Playground

Search fields with a magnifying glass and a clear button.

Text Input — Sizes

Open in Playground

Small, medium, and large fields.

Text Input — States

Please enter a valid email address.
This username is already taken — try adding a number.
URL is valid and reachable.
Open in Playground

Error, warning, and success messages, plus status without a message, disabled, and loading.

Text Input — Status variant

attached (default)
Please enter a valid email address.
Message overlaps directly below the input.
detached
Please enter a valid email address.
Message floats below as a separate element with spacing.
Open in Playground

The status message can sit against the field or float below it.

Text Input — Types

Descriptions can be used to provide additional information about a field.
Open in Playground

Description, password, email, tooltip, required, and optional fields.

Styling the container and the control #

TextInput has two parts you can style:

  • Container: the Field box around the label, the control box, and the status message. Use container-class and container-style.
  • Control: the box that paints the border and background and holds the icons and the clear button. Use control-class and control-style.

Each set stays on its own part. Neither set reaches the native <input>.

Vue
<TextInput
  v-model="name"
  label="Name"
  container-class="my-field"
  :control-style="{ borderRadius: '12px' }"
/>

A class or style written directly on <TextInput> still lands on the control box and applies together with control-class. id, data-*, aria-*, and event listeners land on the native <input>.

Inside an InputGroup, and inside a horizontal-labels FormLayout, no container renders, so container-* has no effect and warns in development. To style an InputGroup, put the class on the InputGroup itself.

Accessibility #

A label is required. Screen readers rely on it to describe what the field is for, and a placeholder is only visible while the field is empty, so it cannot stand in for a label.

The component wires the label, description and status message together with ARIA attributes, so assistive technology reads them as one unit:

  • description and status.message connect to aria-describedby.
  • An error status sets aria-invalid.
  • A required field sets aria-required.

isRequired renders the required indicator and sets the ARIA state. When you also need native browser validation — for example when you rely on form submission to block an incomplete field — pass required as well.

Input methods #

While an input method such as Pinyin or Kana is composing a candidate, the characters the user has typed are not final yet. The component tracks that distinction so a half-finished value never reaches your state:

  • The component does not update v-model while a candidate is still being composed, and the field keeps showing the composing text.
  • Once compositionend fires — the moment the user picks a candidate — the component writes the final text to v-model.
  • Enter used to confirm a candidate does not emit enter. The event fires normally when the user presses Enter again to submit the form.

This keeps validation and submit logic built on v-model from reacting to partial input.