Input group
Input with a leading and trailing add-on, such as https:// or an icon, where the outer box takes the border and focus ring.
pnpm dlx shadcn@latest add @haze/input-group---
import { cn } from "../../../lib/haze/utils";
interface Props {
id: string;
name?: string;
type?: "text" | "email" | "password" | "search" | "url" | "tel" | "number";
placeholder?: string;
/** Text add-on before the input, on a quiet fill. The `leading` slot replaces it and is styled as an icon add-on with no fill. */
leading?: string;
/** Text add-on after the input, on a quiet fill. The `trailing` slot replaces it and is styled as an icon add-on with no fill. */
trailing?: string;
class?: string;
/** Any other input attribute, for example value, required, disabled or aria-describedby. */
[key: string]: unknown;
}
const { id, name = id, type = "text", placeholder, leading, trailing, class: className, ...rest } = Astro.props;
const hasLeading = Astro.slots.has("leading") || Boolean(leading);
const hasTrailing = Astro.slots.has("trailing") || Boolean(trailing);
// A slot add-on is treated as an icon (no fill); a text add-on gets a quiet fill.
const addon = {
text: "flex shrink-0 items-center bg-muted px-3 text-muted-foreground",
icon: "flex shrink-0 items-center px-3 text-muted-foreground [&_svg]:size-4",
};
const leadingClass = Astro.slots.has("leading") ? cn(addon.icon, "pe-0") : cn(addon.text, "border-r border-border");
const trailingClass = Astro.slots.has("trailing") ? cn(addon.icon, "ps-0") : cn(addon.text, "border-l border-border");
---
<div
class={cn(
"flex h-10 w-full min-w-0 items-stretch overflow-hidden rounded-lg border border-frame-input bg-field text-sm",
"transition-[border-color,box-shadow] duration-150 ease-snappy hover:border-frame-foreground",
"has-[:is(input,textarea):focus-visible]:border-ring has-[:is(input,textarea):focus-visible]:ring-3 has-[:is(input,textarea):focus-visible]:ring-ring/24",
"has-[[aria-invalid=true]]:border-destructive! has-[[aria-invalid=true]:focus-visible]:ring-destructive/24",
"has-[:disabled]:cursor-not-allowed has-[:disabled]:bg-muted has-[:disabled]:opacity-50 has-[:disabled]:hover:border-frame-input",
className,
)}
>
{
hasLeading && (
<span class={leadingClass}>
<slot name="leading">{leading}</slot>
</span>
)
}
<input
id={id}
name={name}
type={type}
placeholder={placeholder}
class="h-full min-w-0 flex-1 border-0 bg-transparent px-3 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none text-sm tracking-[-0.01em] text-foreground outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed"
{...rest}
/>
{
hasTrailing && (
<span class={trailingClass}>
<slot name="trailing">{trailing}</slot>
</span>
)
}
</div>When to use
- Showing a fixed prefix or suffix, like a domain, currency or unit
- A search box with a magnifier icon inside the field
- Values where the user should only type the changing part
When not to use
- An add-on that is clickable, such as a Copy button; place a button next to an input instead
- Plain text with no prefix or suffix; use input
Installation
Add the Haze registry to components.json once, then install Input group with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/input-groupnpx shadcn@latest add @haze/input-groupyarn dlx shadcn@latest add @haze/input-groupbunx --bun shadcn@latest add @haze/input-groupFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Input id; reference it from a label or Field. |
| name | string | id | Form field name. |
| type | "text" | "email" | "password" | "search" | "url" | "tel" | "number" | "text" | Input type. |
| placeholder | string | – | Example value shown while empty. |
| leading | string | – | Text add-on before the input, on a quiet fill. |
| trailing | string | – | Text add-on after the input, on a quiet fill. |
| class | string | – | Extra classes on the bordered wrapper. |
| leading slot | slot | – | Replaces the leading text, for example with an icon. Styled as an icon add-on with no fill. |
| trailing slot | slot | – | Replaces the trailing text. |
| ...rest | attributes | – | Any other input attribute, for example value, required, disabled or aria-invalid. |
Keyboard interactions
- Tab
- Focuses the input; the add-ons are not focusable
Accessibility
- Text add-ons sit on a quiet fill with a hairline; icon add-ons have no fill.
- The wrapper draws the focus ring through focus-within, so the whole box lights up while the real input holds focus. A destructive border shows when the input has aria-invalid=true.
- Add-on text is not part of the input's accessible name; repeat the unit in the label or description, for example "Monthly budget in dollars".
- Icons in the slots should be aria-hidden; a meaningful add-on needs text.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Input group" with `npx shadcn@latest add @haze/input-group`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import InputGroup from "@/components/haze/ui/input-group.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/input-group.md
Customize with real content
Adapt the Haze input-group ui for our product. Replace the demo values of these props with our real content: id, name, type, placeholder, leading, trailing, class, leading slot, trailing slot, ...rest. Keep the layout, the heading level rules and these accessibility details: Text add-ons sit on a quiet fill with a hairline; icon add-ons have no fill. The wrapper draws the focus ring through focus-within, so the whole box lights up while the real input holds focus. A destructive border shows when the input has aria-invalid=true. Add-on text is not part of the input's accessible name; repeat the unit in the label or description, for example "Monthly budget in dollars". Icons in the slots should be aria-hidden; a meaningful add-on needs text. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using input-group, check it fits: use it when showing a fixed prefix or suffix, like a domain, currency or unit; a search box with a magnifier icon inside the field; values where the user should only type the changing part. Avoid it when an add-on that is clickable, such as a copy button; place a button next to an input instead; plain text with no prefix or suffix; use input. Alternatives: @haze/input, @haze/field, @haze/button-group.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.