Inputs & controlsstable

    Input

    Plain text fields with separate live examples for default, floating, read-only, invalid, and disabled states. Use InputGroup for icons and adornments.

    Follow the installation and quick start below to use Input in your project, or read the complete setup guide.

    Accessible by designLight & darkCopy. Customize. Ship.
    On this page
    Live previewFluid

    Type a name to try this input.

    Interactive exampleReact / TypeScript / Tailwind CSS
    ADD TO YOUR PROJECT

    Installation

    1. Initialize once

    Run from an existing React project with Node.js 18 or later. Skip this step if the project already has u-lib.json. Initialization copies the shared stylesheet and adds its import to your application entry.

    npx @scriptwithahmad/u-lib@0.2.2 init

    2. Add Input and example components

    This command includes the UI components used by this page's usage examples. The CLI copies editable source into your components directory and installs each component's dependencies. Existing source files are preserved.

    npx @scriptwithahmad/u-lib@0.2.2 add input

    Choose the tab for your package manager. Yarn commands require modern Yarn; Yarn Classic users can use npx. Use --dry-run to preview changes. See the installation guide for custom paths, JavaScript output and package-import alternatives.

    USE IN YOUR APP

    Quick start

    Copy this example into src/Example.tsx (or Example.tsx at the project root when you do not use src). Imports assume the default CLI paths. From a nested file such as src/app/page.tsx, adjust ./components to ../components. Keep the client directive in Next.js when using state or event handlers.

    input-example.tsx
    "use client";
    
    import { Input } from "./components/ui/input";
    import { useState } from "react";
    
    export default function Example() {
      const [value, setValue] = useState("");
      return <div className="w-full max-w-sm space-y-2">
        <Input label="Name" placeholder="Your name" value={value} onChange={event => setValue(event.target.value)} />
        <p className="text-xs text-muted-foreground" aria-live="polite">{value ? `Hello, ${value}!` : "Type a name to try this input."}</p>
      </div>;
    }
    

    Keep the shared stylesheet imported once. Replace sample image URLs and data with your own. Examples may use layout utilities beyond the precompiled component styles; compile added Tailwind classes in your app or replace them with your own CSS. Customize local source or className, and preserve accessible names and keyboard behavior.

    BUILD WITH IT

    Usage examples

    5 examples

    Try each example, then switch to Code to copy its complete implementation. These catalog snippets use the website's @/components/ui alias; replace it with your local generated path as shown in Quick start.

    01

    Default input

    A plain controlled input with an external label. Type to try the change handler; the input has no icons or adornments.

    Default input

    Type a name to try this input.

    02

    Floating label

    The inline label rises when focused or filled. Email remains icon-free; use InputGroup when you want an icon.

    Floating label
    03

    Read-only input

    A native readOnly field can be focused, selected, copied, and submitted when named. It cannot be edited.

    Read-only input
    04

    Invalid input

    Associate error text with aria-describedby and mark the native field invalid. Validation remains under your control.

    Invalid input

    Enter a valid email address.

    05

    Disabled input

    Disabled fields cannot be edited or focused and are omitted from native form submission.

    Disabled input
    THE API

    Props & configuration

    Reference

    Everything you need to fine-tune this component.

    Props and configuration
    PropTypeDefaultDescription
    variant"default" | "floating"defaultDefault places the label above a 48px field; floating places the label inside a 56px field. Supply label for floating.
    labelstring—Real accessible label connected to your id or an automatically generated id. A floating label replaces the placeholder.
    typeHTMLInputTypeAttributetextNative type. Plain Input never adds icons, including for email and password types.
    value / defaultValuestring | number | readonly string[]—Use value with onChange for controlled fields or defaultValue for an uncontrolled field.
    onChangeChangeEventHandler<HTMLInputElement>—Native change event for the editable value.
    disabled / readOnly / requiredbooleanfalseNative editing, focus, validation, and submission behavior. Read-only fields can still be focused and copied.
    aria-invalid / aria-describedbynative input attributes—Mark invalid values and associate helper or error text. Without label, supply an external label or aria-label.
    className / containerClassNamestring—Style the native input or the outer field wrapper. Native input attributes and refs are forwarded.