Input

A versatile input component with support for icons, validation states, and custom styling.

The Input component is a flexible and feature-rich form control that supports various states, icons, validation, and custom styling. It's designed to be accessible and user-friendly while maintaining a consistent look and feel.

Import

import { Input } from 'h2o-library';

Basic Usage

Simple Input

<Input 
  label="Username"
  placeholder="Enter your username"
/>

Input with Value

<Input 
  label="Controlled Input"
  value="Hello World"
  onChange={(e) => console.log(e.target.value)}
/>

Input Sizes

<Input 
  size="sm"
  label="Small Input"
  placeholder="Small size..."
/>
<Input 
  size="md"
  label="Medium Input"
  placeholder="Medium size..."
/>
<Input 
  size="lg"
  label="Large Input"
  placeholder="Large size..."
/>

Input with Icons

<Input 
  label="Left Icon"
  leftIcon="search"
  placeholder="Search..."
/>
<Input 
  label="Right Icon"
  rightIcon="info"
  placeholder="With right icon..."
/>

Password Input

<Input 
  label="Password"
  type="password"
  placeholder="Enter password..."
/>

Input with Tooltip

<Input 
  label="With Tooltip"
  tooltip="This is a helpful tooltip"
  placeholder="Hover over the info icon..."
/>

Interactive Examples

For interactive examples including all features and states, check out our example component:

Basic Inputs

Input Sizes

Input with Icons

Password Input

Input States

This field is required
This is a helpful note

Input with Clear

Input with Tooltip

Props

PropTypeDefaultDescription
labelstring-The label text for the input
size"sm" | "md" | "lg""md"The size of the input
leftIconIconType-Icon to display on the left side
rightIconIconType-Icon to display on the right side
onRightIconClick() => void-Callback when right icon is clicked
showClearbooleanfalseWhether to show a clear button
notestring-Helper text below the input
errorstring-Error message below the input
containerClassNamestring-Additional CSS classes for the container
tooltipstring-Tooltip text for the info icon
tooltipPositionTooltipPosition"top"Position of the tooltip

Plus all standard HTML input attributes except size.

Design Considerations

  • Clear visual hierarchy with labels and helper text
  • Consistent spacing and alignment
  • Visual feedback for different states (focus, error, disabled)
  • Support for both controlled and uncontrolled usage
  • Flexible icon placement and interaction
  • Password visibility toggle
  • Clear button for easy value reset
  • Tooltip support for additional information
  • Custom styling options for both container and input

Accessibility

  • Proper label association with inputs
  • Clear focus states
  • Error messages are properly announced
  • Helper text provides additional context
  • Icons are decorative and don't interfere with screen readers
  • Password visibility toggle is keyboard accessible
  • Clear button is properly labeled
  • Tooltips are accessible via keyboard
  • ARIA attributes are automatically handled
  • Screen readers announce the current state and any errors