Text Input
Alignment target:@astryxdesign/core v0.7.1 · TextInput
Usage #
TextInput accepts single-line text. The component includes Field.
<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:
import '@astryx-vue/themes/neutral.css'Anatomy
| Element | Description |
|---|---|
| Label | Text that identifies the field. Always rendered for accessibility even when visually hidden. |
| Description | Helper text between the label and the input that provides additional context or formatting hints. |
| Start icon | A leading icon inside the input that hints at the expected content, like a magnifying glass for search. |
| Placeholder | Hint text shown when the input is empty. Disappears on focus. |
| Clear button | A trailing × button that resets the value and returns focus to the input. |
| Spinner | Loading indicator that appears during async actions like server-side validation. |
| Status icon | A trailing icon (error, warning, or success) that communicates validation state. |
Best practices #
| Guidance | Practices |
|---|---|
| Do | Always 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. |
| Do | Use validation status with a message to explain what went wrong: "Email must include @" is better than just turning the border red. |
| Do | Size 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. |
| Do | Add a clear button for search and filter inputs so users can quickly reset without selecting all text. |
Examples #
Text Input — Icon
Name, email, and password fields with a leading icon.
Text Input — Search
Search fields with a magnifying glass and a clear button.
Text Input — Sizes
Small, medium, and large fields.
Text Input — States
Error, warning, and success messages, plus status without a message, disabled, and loading.
Text Input — Status variant
The status message can sit against the field or float below it.
Text Input — Types
Description, password, email, tooltip, required, and optional fields.
Styling the container and the control #
TextInput has two parts you can style:
- Container: the
Fieldbox around the label, the control box, and the status message. Usecontainer-classandcontainer-style. - Control: the box that paints the border and background and holds the icons and the clear button. Use
control-classandcontrol-style.
Each set stays on its own part. Neither set reaches the native <input>.
<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:
descriptionandstatus.messageconnect toaria-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-modelwhile a candidate is still being composed, and the field keeps showing the composing text. - Once
compositionendfires — the moment the user picks a candidate — the component writes the final text tov-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.