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.
On this page
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 init2. 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-group3. Install example dependencies
These packages are imported directly by the examples. Some may already have been installed by the CLI.
npm install lucide-reactChoose 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.
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.
"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.
Usage 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.
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.
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.
What customers would pay
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.
Choose HTTP or HTTPS, then enter your site name without the domain ending.
Search with custom icon
Use icon for a custom leading icon. Pass icon={null} to hide automatic email or password icons.
Floating group
A floating label with an email icon. Floating fields stay 56px tall so the label and value have room.
Comfortable group
Choose comfortable for the larger 48px field. The compact 34px density remains the default.
Invalid price
error links the message automatically and marks the field invalid. Error styling stays visible during hover and focus.
Enter a price greater than zero.
Disabled group
The label, icon, frame, and adornments dim together. Native disabled behavior prevents editing and focus.
Props & configuration
Everything you need to fine-tune this component.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "floating" | default | Default shows the label above the field. Floating shows an inline label in a 56px field; supply label. |
label | string | — | Real accessible label connected to your id or an automatically generated id. A floating label replaces the placeholder. |
type | HTMLInputTypeAttribute | text | Native input type. Email and password include Mail and LockKeyhole icons automatically; pass icon={null} to hide them. |
value / defaultValue | string | number | readonly string[] | — | Use value with onChange for controlled fields or defaultValue for an uncontrolled field. |
onChange | ChangeEventHandler<HTMLInputElement> | — | Native change event for the editable value. |
disabled / readOnly / required | boolean | false | Native editing, focus, validation, and submission behavior. Read-only fields can still be focused and copied. |
aria-invalid / aria-describedby | native input attributes | — | Mark invalid values and associate helper or error text. Without label, supply an external label or aria-label. |
className / containerClassName | string | — | Style the native input or the outer field wrapper. Native input attributes and refs are forwarded. |
density | "compact" | "comfortable" | compact | Compact uses a 34px rounded frame matching the email and price reference. Comfortable uses a 48px frame. Floating fields remain 56px. |
icon | ReactNode | — | Custom decorative leading icon. Pass null to disable automatic type icons. Icon and prefix can be used together. |
prefix / postfix | ReactNode | — | 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. |
description | string | — | Helper text below the field, automatically associated with aria-describedby. Existing aria-describedby ids are preserved. |
error | string | — | Visible error text; automatically sets aria-invalid, associates the message, and colors the frame. Takes priority over hover/focus styling. |
protocolSelector | boolean | false | Shows 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. |
