Skip to content

TextField

A complete form field component that combines input, label, description, and error message.

Import

vue
<script setup lang="ts">
import { TextField } from '@heroui-vue/vue'
</script>

Usage

Basic

We'll never share your email.
Password is too short.

<template>
  <div class="flex flex-col gap-4">
    <TextField label="Username" placeholder="Enter username" />
    <TextField label="Email" type="email" placeholder="you@example.com" description="We'll never share your email." />
    <TextField label="Password" type="password" placeholder="••••••••" error="Password is too short." />
  </div>
</template>

<script setup>
import { TextField } from '@heroui-vue/vue'
</script>

With Description

vue
<template>
  <TextField 
    label="Username"
    description="Choose a unique username"
    placeholder="Enter username"
  />
</template>

With Error

vue
<template>
  <TextField 
    label="Password"
    :error="hasError ? 'Password must be at least 8 characters' : undefined"
    v-model="password"
  />
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'

const password = ref('')
const hasError = computed(() => password.value.length > 0 && password.value.length < 8)
</script>

Required

vue
<template>
  <TextField 
    label="Full Name"
    required
    placeholder="Enter your full name"
  />
</template>

Disabled

vue
<template>
  <TextField 
    label="Disabled Field"
    :disabled="true"
    value="Cannot edit this"
  />
</template>

Input Types

vue
<template>
  <TextField label="Email" type="email" />
  <TextField label="Password" type="password" />
  <TextField label="Number" type="number" />
  <TextField label="URL" type="url" />
  <TextField label="Tel" type="tel" />
</template>

With Prefix/Suffix

vue
<template>
  <TextField label="Website">
    <template #prefix>https://</template>
    <template #suffix>.com</template>
  </TextField>

  <TextField label="Price">
    <template #prefix>$</template>
  </TextField>
</template>

API

TextField Props

PropTypeDefaultDescription
modelValuestring-The field value
labelstring-The field label
descriptionstring-The field description
placeholderstring-The input placeholder
typestring'text'The input type
requiredbooleanfalseWhether the field is required
disabledbooleanfalseWhether the field is disabled
readonlybooleanfalseWhether the field is read-only

TextField Events

EventTypeDescription
update:modelValue(value: string) => voidFired when value changes
blur(event: FocusEvent) => voidFired when field loses focus
focus(event: FocusEvent) => voidFired when field receives focus

TextField Slots

SlotDescription
labelCustom label content
descriptionCustom description content
prefixContent before the input
suffixContent after the input

Accessibility

  • TextField combines all form field elements with proper associations
  • Label is properly linked to input via for attribute
  • Description uses aria-describedby
  • Error messages use aria-describedby and aria-invalid
  • Required fields are indicated with aria-required
  • Full keyboard navigation support

Released under the Apache-2.0 License.