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.

`} language='astro' filename='Types.astro' />

Icons

You can add icons to the left or right of the input text using iconLeft or iconRight properties.

`} language='astro' filename='Icons.astro' />

Addons

Use addonLeft and addonRight to append or prepend static text elements to the input.

@
.example.com
$
USD
.example.com
$
USD
`} language='astro' filename='Addons.astro' />

Textarea (Multiline)

Use the multiline prop or type="textarea" to render a textarea instead of an input field.

States

Inputs can display error messages or be disabled to prevent interaction.

This field is required

`} language='astro' filename='States.astro' />

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.

`} language='astro' filename='Formatting.astro' />

Autocomplete

You can provide a list prop that matches the ID of a <datalist> element to enable native browser autocomplete functionality.

`} language='astro' filename='Autocomplete.astro' />

How to Use

To use the TextInput component, import it from its location and pass the required props.

example.astro
---
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

Property
Description
Type
Default

type

Type of the input element string 'text'

label

Label text for the input string

iconLeft

Icon to display on the left side IconName

iconRight

Icon to display on the right side IconName

addonLeft

Addon text to display on the left side string

addonRight

Addon text to display on the right side string

formatOptions

Options for formatting the input value Intl.NumberFormatOptions

locale

Locale for formatting the input value string

value

Value of the input string | number

multiline

Whether the input should be a textarea 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