TextInput
The TextInput component is a form primitive for capturing user text input. It supports labels, errors, and standard HTML input attributes.
Example Usage
Input Types
The component supports all standard input types like text, email, password, etc.
Icons
You can add icons to the left or right of the input text using iconLeft or iconRight properties.
Addons
Use addonLeft and addonRight to append or prepend
static text elements to the input.
Textarea (Multiline)
Use the multiline prop or type="textarea" to render
a textarea instead of an input field.
<TextInput
id='inp-textarea'
type='textarea'
label='Message'
placeholder='Type your message here...'
/> States
Inputs can display error messages or be disabled to prevent interaction.
This field is required
Number Formatting
The TextInput component natively supports JavaScript's built-in Intl.NumberFormat logic. Simply pass the formatOptions prop to format inputs
as currencies, percentages, or numbers with specific grouping.
Autocomplete
You can provide a list prop that matches the ID of a <datalist> element to enable native browser autocomplete functionality.
How to Use
To use the TextInput component, import it from its location and pass the required props.
---
import TextInput from '@/components/data-entry/TextInput.astro';
---
<form action="/submit">
<TextInput
id="email"
type="email"
label="Email Address"
placeholder="Enter your email"
required
/>
</form> API
| Eigenschaft | Beschreibung | Typ | Standard |
|---|---|---|---|
| type | Typ des Eingabeelements | string | 'text' |
| label | Beschriftungstext für die Eingabe | string | |
| iconLeft | Symbol zur Anzeige auf der linken Seite | IconName | |
| iconRight | Symbol zur Anzeige auf der rechten Seite | IconName | |
| addonLeft | Zusatztext zur Anzeige auf der linken Seite | string | |
| addonRight | Zusatztext zur Anzeige auf der rechten Seite | string | |
| formatOptions | Optionen zur Formatierung des Eingabewerts | Intl.NumberFormatOptions | |
| locale | Gebietsschema zur Formatierung des Eingabewerts | string | |
| value | Wert der Eingabe | string | number | |
| multiline | Ob die Eingabe ein Textbereich sein soll | boolean | false |
| error | Indicates an error state or displays an error message | string | boolean | |
| success | Indicates a success state or displays a success message | string | boolean | |
| disabled | Disables the component | boolean | false |