# 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.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/input-group`
- File: `src/components/haze/ui/input-group.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/input-group

## Use 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 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
- [input](https://hazeui.com/ui/input.md)
- [field](https://hazeui.com/ui/field.md)
- [button-group](https://hazeui.com/ui/button-group.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Input id; reference it from a label or Field. |
| name | `string` | id | no | Form field name. |
| type | `"text" \| "email" \| "password" \| "search" \| "url" \| "tel" \| "number"` | "text" | no | Input type. |
| placeholder | `string` |  | no | Example value shown while empty. |
| leading | `string` |  | no | Text add-on before the input, on a quiet fill. |
| trailing | `string` |  | no | Text add-on after the input, on a quiet fill. |
| class | `string` |  | no | Extra classes on the bordered wrapper. |
| leading slot | `slot` |  | no | Replaces the leading text, for example with an icon. Styled as an icon add-on with no fill. |
| trailing slot | `slot` |  | no | Replaces the trailing text. |
| ...rest | `attributes` |  | no | Any other input attribute, for example value, required, disabled or aria-invalid. |

## 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.
- Key Tab: Focuses the input; the add-ons are not focusable

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Add a site address input with https:// before and .haze.dev after
- Make a search input with a leading magnifier icon

## Source

```astro
---
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>
```
