Form controls

TextField
v2.1.2
Documentation Under Review

A versatile single-line text input component with icon slots, tag support, and validation states optimized for product interfaces.

Overview

The Product TextField component provides a flexible, single-line text input optimized for product interfaces. It features a slot-based architecture for icons and tags, multiple input types, validation states, and product-specific typography scaling.

Installation

npm install @pmi/catalyst-text-field

Usage

Basic TextField

Preview

Variants

Sizes

The Product TextField component supports three size variants with product-optimized icon scaling.

Preview

States

Danger State

Use the danger prop to indicate validation errors or warning states.

Preview

Disabled State

The disabled state prevents user interaction and reduces opacity.

Preview

Sizes

The Product TextField supports three size variants with product-optimized typography: sm, md (default), and lg.

Preview

States

Danger State

Use the danger prop to indicate validation errors or warning states.

Preview

Disabled State

The disabled state prevents user interaction and reduces opacity to 40%.

Preview

All States

Preview

Advanced Examples

Character Counter with Validation

Real-time character counting with validation feedback for admin interfaces.

Preview

Character Limit Reached

TextField with character limit already reached, showing error state with validation feedback.

Preview
Error: Maximum characters are 13

With Helper Text

TextField with informative helper text below the input for user guidance.

Preview
Subtext

Tag Input for Categories

Use tags inside text fields for category management and filtering.

Preview
Frontend
Backend

Password Field with Toggle

Security-focused password input with show/hide functionality.

Preview

Real-World Examples

Custom Styling

Payment Field

Credit card input with payment method selection and automatic formatting.

Preview

File Upload Field

File input with validation, preview, and clear functionality.

Preview
SVG, PNG, JPG or GIF (MAX. 800x400px).

Phone Number Field

International phone number input with country selection and validation.

Preview
Enter your phone number including area code

Accessibility

The Product TextField component follows WCAG 2.1 AA guidelines:

  • Semantic HTML: Uses native <input> element for proper form integration
  • ARIA Labels: Associate with <Label> component using htmlFor and id attributes
  • ARIA Descriptions: Use aria-describedby to connect with helper text or error messages
  • ARIA Invalid: Set aria-invalid="true" when in danger/error state
  • Role Alert: Use role="alert" on error messages for immediate screen reader announcement
  • Focus Management: Clear focus indicators with 1px inset ring meeting contrast requirements
  • Keyboard Navigation: Full keyboard support with standard input interactions
  • Input Types: Proper type attributes optimize mobile keyboards and browser behavior
  • Screen Reader Labels: Use .sr-only for icon-only content (e.g., "Error:")

API Reference

TextFieldRoot Props

PropTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Controls height and typography scale (compact/standard/emphasized)
dangerbooleanfalseApplies error/warning styling with red color scheme
disabledbooleanfalseDisables the text field and reduces opacity to 40%
unstyledbooleanfalseDisables all default CVA/Tailwind styling, only applies className.
asChildbooleanfalseEnables composition by merging props onto child element
classNamestring-Additional CSS classes for custom styling

TextFieldInput Props

PropTypeDefaultDescription
type'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number' | 'date' | 'time' | 'month' | 'week' | 'datetime-local''text'HTML input type for different input behaviors and mobile keyboards
placeholderstring-Placeholder text when input is empty
valuestring-Controlled value for state management
defaultValuestring-Initial uncontrolled value
onChange(e: ChangeEvent<HTMLInputElement>) => void-Change event handler
disabledbooleanfalseDisables the input
maxLengthnumber-Maximum character limit (enforced by browser)
minLengthnumber-Minimum character limit for validation
requiredbooleanfalseMarks the field as required
aria-labelstring-Accessible label for screen readers
aria-describedbystring-ID of element describing the input
aria-invalidboolean | 'true' | 'false'-Indicates validation state
aria-requiredboolean | 'true' | 'false'-Indicates if field is required
unstyledbooleanfalseDisables all default CVA/Tailwind styling, only applies className.
asChildbooleanfalseEnables composition by merging props onto child element

TextFieldSlot Props

PropTypeDefaultDescription
side'left' | 'right'-Position of the slot within the text field
asChildbooleanfalseEnables composition by merging props onto child element
unstyledbooleanfalseDisables all default CVA/Tailwind styling, only applies className.
classNamestring-Additional CSS classes for custom styling
  • Label - For labeling form fields (shared component)
  • SubText - For helper text and validation messages (shared component)
  • TextArea - For multi-line text input
  • Button - For interactive controls within slots
  • Tag - For tag chip patterns

Best Practices

  1. Label Association: Always associate TextField with a Label using htmlFor/id
  2. Input Types: Use appropriate type attributes for better mobile keyboards and validation
  3. Icon Sizing: Use xs/sm/md for sm/md/lg sizes respectively (product-specific scaling)
  4. Validation Timing: Provide immediate feedback on form submission, clear errors on input change
  5. Placeholder Text: Keep placeholder text concise and action-oriented for product interfaces
  6. Character Limits: Show character counters when enforcing maxLength for user guidance
  7. Helper Text: Use SubText to provide context for technical or admin-specific fields
  8. Password Security: Always include show/hide toggle and strength indicators where applicable
  9. Error Specificity: Make error messages specific and actionable for technical users
  10. Loading States: Disable and show loading feedback during API operations
  11. Monospace Font: Use font-mono for code, API keys, and technical identifiers
  12. Dense Layouts: Use sm size for compact admin interfaces and data grids

On this page