Inputs & controlsstable

    Input Group

    Explore each grouped input separately: email, price, website, search, floating labels, validation, and disabled fields. Every preview includes its matching code.

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

    Accessible by designLight & darkCopy. Customize. Ship.
    On this page
    Live previewFluid
    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 Group 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-group

    3. Install example dependencies

    These packages are imported directly by the examples. Some may already have been installed by the CLI.

    npm install lucide-react

    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-group-example.tsx
    "use client";
    
    import { InputGroup } from "./components/ui/input-group";
    
    export default function Example() {
      return <div className="w-full max-w-sm space-y-2">
        <InputGroup label="Email address" type="email" placeholder="name@email.com" autoComplete="email" required />
      </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

    8 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

    Email with icon

    A compact 34px field with an automatic email icon and native required validation. The red asterisk is decorative; required conveys the state to assistive technology.

    Email with icon
    02

    Price with prefix and postfix

    Combine a dollar prefix, a USD postfix, and helper text. Only the editable number belongs to the value. Meaningful units are included in the accessible name.

    Price with prefix and postfix

    What customers would pay

    03

    Website with prefix and postfix

    Select one of the predefined HTTP or HTTPS protocols inside the field. HTTPS is selected initially. protocol and onProtocolChange let you control the selection; only the site name is editable. Build the full URL from protocol, site name, and the domain ending when submitting.

    Website with prefix and postfix

    Choose HTTP or HTTPS, then enter your site name without the domain ending.

    04

    Search with custom icon

    Use icon for a custom leading icon. Pass icon={null} to hide automatic email or password icons.

    Search with custom icon
    05

    Floating group

    A floating label with an email icon. Floating fields stay 56px tall so the label and value have room.

    Floating group
    06

    Comfortable group

    Choose comfortable for the larger 48px field. The compact 34px density remains the default.

    Comfortable group
    07

    Invalid price

    error links the message automatically and marks the field invalid. Error styling stays visible during hover and focus.

    Invalid price

    Enter a price greater than zero.

    08

    Disabled group

    The label, icon, frame, and adornments dim together. Native disabled behavior prevents editing and focus.

    Disabled group
    THE API

    Props & configuration

    Reference

    Everything you need to fine-tune this component.

    Props and configuration
    PropTypeDefaultDescription
    variant"default" | "floating"defaultDefault shows the label above the field. Floating shows an inline label in a 56px field; supply label.
    labelstring—Real accessible label connected to your id or an automatically generated id. A floating label replaces the placeholder.
    typeHTMLInputTypeAttributetextNative input type. Email and password include Mail and LockKeyhole icons automatically; pass icon={null} to hide them.
    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.
    density"compact" | "comfortable"compactCompact uses a 34px rounded frame matching the email and price reference. Comfortable uses a 48px frame. Floating fields remain 56px.
    iconReactNode—Custom decorative leading icon. Pass null to disable automatic type icons. Icon and prefix can be used together.
    prefix / postfixReactNode—Decorative leading or trailing text/icons. Not editable, not submitted, and hidden from assistive technology. Include meaningful units in label or description. Keep these slots short and place interactive buttons next to the input.
    descriptionstring—Helper text below the field, automatically associated with aria-describedby. Existing aria-describedby ids are preserved.
    errorstring—Visible error text; automatically sets aria-invalid, associates the message, and colors the frame. Takes priority over hover/focus styling.
    protocolSelectorbooleanfalseShows the shared styled HTTP/HTTPS dropdown inside the leading edge instead of prefix. Defaults to HTTPS, supports keyboard navigation, and follows disabled/readOnly.
    protocol"http" | "https"—Optional controlled protocol value when protocolSelector is enabled. Without it, the selector manages its own state and starts at https.
    onProtocolChange(protocol: "http" | "https") => void—Called when HTTP or HTTPS is selected. Combine the protocol with the native input value yourself; neither the selector nor the decorative postfix is included in that value.