# InputGroup

Draws one field chrome around an `Input` and addons on either side, such as an icon, a prefix or a button. A click on a bare part of the group focuses the input.

## Use for

- an input with a leading icon or prefix
- an input with a trailing button, such as show password or clear

## Practices

- Do: Use `InputGroup.Input`, so the input takes the group size and drops its own chrome.
- Do: Put a `Button` in an addon without size or variant props. The addon sizes it as a square neutral ghost button to fit the group.
- Don't: Render `InputGroup.Start` or `InputGroup.End` outside `InputGroup.Root`. They throw.

## API reference

### InputGroup.Root

A `div` that draws the chrome and carries `data-size`, `data-disabled` and `data-invalid`.

Slot: `cl-input-group`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `InputGroupSize` | `'md'` | `sm`, `md` or `lg`. The input and addon buttons follow it. |
| `disabled` | `boolean` | `` the enclosing `Field`'s, else `false` `` | Disables the input and addon buttons. |
| `invalid` | `boolean` | `` the enclosing `Field`'s, else `false` `` | Marks the input `aria-invalid`. |

### InputGroup.Input

The `Input`, as a `ghost` input sized by the group.

Slot: `cl-input`

### InputGroup.Start

A `span` before the input. Sets the defaults for any `Button` inside it.

Slot: `cl-input-group-start`

### InputGroup.End

A `span` after the input. Sets the defaults for any `Button` inside it.

Slot: `cl-input-group-end`

## Examples

### A search input

```tsx
<InputGroup.Root>
  <InputGroup.Start>
    <Icon glyph={MagnifyingGlass} />
  </InputGroup.Start>
  <InputGroup.Input type='search' aria-label='Search' />
</InputGroup.Root>
```

## Related

- [Input](/docs/components/input.md)
- [PasswordInput](/docs/components/password-input.md)
- [PhoneInput](/docs/components/phone-input.md)
- [Field](/docs/components/field.md)
