Unkey
Components

FormInput

A form input component with built-in label, description, and error handling capabilities.

FormInput

A comprehensive form input component that combines labels, descriptions, and validation states. Perfect for creating accessible, user-friendly forms with proper labeling and helpful context.

Default

The default FormInput includes a label and optional description text, providing clear context for users.

Choose a unique username for your account

Input States

Required Field

Use the required prop to indicate mandatory fields. This automatically adds an asterisk (*) to the label.

We'll send your confirmation email here

Success State

Indicates successful validation or acceptance of input value. The success icon and text provide positive feedback.

Your API key has been verified

Warning State

Used for potentially problematic inputs that don't prevent form submission. Includes a warning icon and explanatory text.

Your password is about to expire

Error State

Shows validation errors or other issues that need user attention. Features prominent error styling and message.

Disabled State

Apply when the field should be non-interactive, such as during form submission or based on other field values.

Contact admin to change organization ID

With Default Value

Pre-populated input with an initial value that users can modify.

Name of your new project

Read-only State

For displaying non-editable information while maintaining form layout consistency.

Copy this token for your records

Complex Usage

Example of a FormInput with multiple props configured for a specific use case.

Enter the URL where we'll send event notifications

Props

The FormInput component extends the standard Input component props with additional form-specific properties:

PropTypeDefault
label
string
-
description
string
-
required
boolean
-
error
string
-
id
string
-
className
string
-
variant
"default" | "success" | "warning" | "error"
-

Accessibility

FormInput is built with accessibility in mind:

  • Labels are properly associated with inputs using htmlFor/id
  • Error messages are announced to screen readers using role="alert"
  • Required fields are marked both visually and via aria-required
  • Helper text is linked to inputs using aria-describedby
  • Error states are indicated using aria-invalid

Best Practices

When using the FormInput component:

  • Always provide clear, concise labels
  • Use description text to provide additional context when needed
  • Keep error messages specific and actionable
  • Use required fields sparingly and logically
  • Group related FormInputs using fieldset and legend when appropriate
  • Consider the mobile experience when writing labels and descriptions
  • Maintain consistent validation patterns across your form
  • Use appropriate input types (email, tel, etc.) for better mobile keyboards
  • Consider character/word limits in descriptions and error messages
  • Test with screen readers to ensure accessibility

Layout Guidelines

  • Labels should be clear and concise
  • Error messages should appear immediately below the input
  • Description text should be helpful but not too lengthy

On this page